feat: 首页改版
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
---
|
||||
import Eye from "@/assets/icon/eye.png?url";
|
||||
import Folder from "@/assets/icon/folder.png?url";
|
||||
import Calendar from "@/assets/icon/calendar.png?url";
|
||||
import type {Post} from "@/types/post";
|
||||
import {formatDatetime} from "@/lib/format.ts";
|
||||
|
||||
@@ -11,155 +14,232 @@ interface Props {
|
||||
const {posts, page, totalPage} = Astro.props
|
||||
|
||||
posts.map((post) => {
|
||||
post.published_at = formatDatetime(post.published_at, 'YYYY 年 M 月 D 日')
|
||||
post.published_at = formatDatetime(post.published_at, 'YYYY-MM-DD')
|
||||
})
|
||||
---
|
||||
|
||||
<div class="posts">
|
||||
{
|
||||
posts.map((post) => (
|
||||
<a class="post" href={`/posts/${post.slug}`}>
|
||||
<div class="published-at">{post.published_at}</div>
|
||||
<div class="category-name">{post.category_name}</div>
|
||||
<div class="post-title">{post.title}</div>
|
||||
<div class="link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="lucide lucide-arrow-up-right-icon lucide-arrow-up-right">
|
||||
<path d="M7 7h10v10"/>
|
||||
<path d="M7 17 17 7"/>
|
||||
</svg>
|
||||
</div>
|
||||
<section class="section">
|
||||
<div class="post-list">
|
||||
{posts.map(post => (
|
||||
<a href={`/post/${post.slug}`}>
|
||||
<article class="post-card">
|
||||
<div class="post-cover">
|
||||
<img src={post.cover} alt={post.title} loading="lazy"/>
|
||||
</div>
|
||||
<div class="post-body">
|
||||
<div class="post-meta">
|
||||
<span>
|
||||
<img src={Calendar} alt="Calendar"/>
|
||||
{post.published_at}
|
||||
</span>
|
||||
<span>
|
||||
<img src={Folder} alt="Folder"/>
|
||||
{post.category_name}
|
||||
</span>
|
||||
<span>
|
||||
<img src={Eye} alt="Eye"/>
|
||||
{post.view}
|
||||
</span>
|
||||
</div>
|
||||
<h3 class="post-title">
|
||||
{post.title}
|
||||
</h3>
|
||||
<div class="post-summary">
|
||||
{post.summary}
|
||||
</div>
|
||||
<!--<div class="tags">-->
|
||||
<!-- <div class="tag">HTML</div>-->
|
||||
<!-- <div class="tag">CSS</div>-->
|
||||
<!-- <div class="tag">响应式</div>-->
|
||||
<!--</div>-->
|
||||
</div>
|
||||
</article>
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<!--分页器-->
|
||||
{totalPage>1&&
|
||||
<div class="pagination">
|
||||
{page > 1 ? (<a href={`/page/${page - 1}`}>上一页</a>) : (
|
||||
<span class="disabled" aria-disabled="true">上一页</span>)}
|
||||
|
||||
{Array.from({length: totalPage}).map((_, index) => {
|
||||
if (page === index + 1) {
|
||||
return <span class="pagination-number disabled" aria-disabled="true">{index + 1}</span>
|
||||
}
|
||||
return <a class="pagination-number" href={`/page/${index + 1}`}>{index + 1}</a>
|
||||
})}
|
||||
|
||||
{page < totalPage ? (<a href={`/page/${page + 1}`}>下一页</a>) : (
|
||||
<span class="disabled" aria-disabled="true">下一页</span>)}
|
||||
</div>}
|
||||
<!--分页器-->
|
||||
{totalPage > 1 &&
|
||||
<nav class="pagination" aria-label="分页">
|
||||
{page > 1 ? <a href={`/page/${page - 1}`} class="link">« 上一页</a> : <span class="link disabled">« 上一页</span>}
|
||||
{Array.from({length: totalPage}).map((_, index) => {
|
||||
if (page === index + 1) {
|
||||
return <span class="link current">{index + 1}</span>
|
||||
}
|
||||
return <a class="link" href={`/page/${index + 1}`}>{index + 1}</a>
|
||||
})}
|
||||
{page < totalPage ? <a href={`/page/${page + 1}`} class="link">下一页 »</a> :
|
||||
<span class="link disabled">下一页 »</span>}
|
||||
</nav>}
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.posts {
|
||||
.section {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.post {
|
||||
padding: 16px;
|
||||
.post-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
box-shadow: rgba(0, 0, 0, 0.05) 0px 1px 2px 0px;
|
||||
box-shadow: var(--shadow);
|
||||
padding: 20px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.post-card:hover {
|
||||
transform: translateY(-3px);
|
||||
box-shadow: var(--shadow-hover);
|
||||
}
|
||||
|
||||
.post-cover {
|
||||
flex-shrink: 0;
|
||||
width: 160px;
|
||||
height: 110px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: transform 0.2s linear;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.post:hover {
|
||||
box-shadow: rgba(33, 35, 38, 0.1) 0px 10px 10px -10px;
|
||||
}
|
||||
|
||||
.published-at {
|
||||
white-space: nowrap;
|
||||
font-size: 14px;
|
||||
color: #4b5563;
|
||||
min-width: 130px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
border-radius: 999px;
|
||||
background: #fceeda;
|
||||
padding: 4px 12px;
|
||||
font-size: 14px;
|
||||
margin-right: 24px;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
justify-content: center;
|
||||
font-size: 40px;
|
||||
color: #fff;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.link {
|
||||
.post-cover img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.link svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
color: #6b7280;
|
||||
.post-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin: 24px 0;
|
||||
.post-meta {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 6px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.pagination-number {
|
||||
.post-meta span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.post-meta span img {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.post-summary {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 12px;
|
||||
color: #4f6df5;
|
||||
background: #eef1fe;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
color: #fafafa;
|
||||
background: #1f2937;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.tag:hover {
|
||||
background: #dfe6fd;
|
||||
}
|
||||
|
||||
|
||||
/* ========== 分页 ========== */
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 32px;
|
||||
}
|
||||
|
||||
.link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 38px;
|
||||
height: 38px;
|
||||
padding: 0 12px;
|
||||
border-radius: 8px;
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border);
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.pagination .disabled {
|
||||
color: #9ca3af;
|
||||
.link:hover,
|
||||
.link.current {
|
||||
background: var(--primary);
|
||||
border-color:var(--primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.link.disabled {
|
||||
color: var(--text-secondary);
|
||||
background: var(--card-bg);
|
||||
border-color: var(--border);
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.pagination-number.disabled {
|
||||
background: #d1d5db;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.posts {
|
||||
gap: 12px;
|
||||
@media (max-width: 860px) {
|
||||
.post-card {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.published-at {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
display: none;
|
||||
.post-cover {
|
||||
width: 128px;
|
||||
height: 88px;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.dark) .post {
|
||||
background: #171717;
|
||||
@media (max-width: 560px) {
|
||||
.post-card {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.dark) .published-at {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
:global(.dark) .category-name {
|
||||
background: #e5e5e5;
|
||||
color: #0a0a0a;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user