refactor: 重写filter页面 更新为search
This commit is contained in:
@@ -23,7 +23,7 @@ const { data: tags } =
|
||||
categories.map((category) => (
|
||||
<li>
|
||||
<a
|
||||
href={`/filter?type=category&code=${encodeURIComponent(category.code)}`}
|
||||
href={`/search?c=${encodeURIComponent(category.code)}`}
|
||||
title={`${category.name} · ${category.post_count} 篇`}
|
||||
>
|
||||
{category.name}
|
||||
@@ -45,7 +45,7 @@ const { data: tags } =
|
||||
tags.map((tag) => (
|
||||
<a
|
||||
class="tag"
|
||||
href={`/filter?type=tag&code=${encodeURIComponent(tag.code)}`}
|
||||
href={`/search?t=${encodeURIComponent(tag.code)}`}
|
||||
>
|
||||
{tag.name}
|
||||
</a>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
import type { Post } from "@/types/post";
|
||||
import type {Post} from "@/types/post";
|
||||
import IndexSidebar from "@/components/IndexSidebar.astro";
|
||||
import PostList from "@/components/PostList.astro";
|
||||
import PostList from "@/components/Post/List.astro";
|
||||
import Pagination from "@/components/Post/Pagination.astro";
|
||||
|
||||
interface Props {
|
||||
posts: Post[];
|
||||
@@ -9,13 +10,16 @@ interface Props {
|
||||
totalPage: number;
|
||||
}
|
||||
|
||||
const { posts, page, totalPage } = Astro.props;
|
||||
const {posts, page, totalPage} = Astro.props;
|
||||
---
|
||||
|
||||
<div class="page-content">
|
||||
<div class="container">
|
||||
<PostList posts={posts} page={page} totalPage={totalPage} />
|
||||
<IndexSidebar />
|
||||
<div class="post-container">
|
||||
<PostList posts={posts}/>
|
||||
<Pagination page={page} totalPage={totalPage}/>
|
||||
</div>
|
||||
<IndexSidebar/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -26,6 +30,12 @@ const { posts, page, totalPage } = Astro.props;
|
||||
gap: 28px;
|
||||
}
|
||||
|
||||
.post-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.container {
|
||||
flex-direction: column;
|
||||
|
||||
@@ -1,88 +1,54 @@
|
||||
---
|
||||
import type {Post} from '@/types';
|
||||
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";
|
||||
import LazyImage from "@/components/LazyImage.astro";
|
||||
import {formatDatetime} from "@/lib/format.ts";
|
||||
|
||||
interface Props {
|
||||
posts: Post[]
|
||||
page: number
|
||||
totalPage: number
|
||||
post: Post
|
||||
}
|
||||
|
||||
const {posts, page, totalPage} = Astro.props
|
||||
|
||||
posts.map((post) => {
|
||||
post.published_at = formatDatetime(post.published_at, 'YYYY-MM-DD')
|
||||
})
|
||||
const {post} = Astro.props;
|
||||
const published_at = formatDatetime(post.published_at, 'YYYY-MM-DD')
|
||||
---
|
||||
<section class="section">
|
||||
<div class="post-list">
|
||||
{posts.map(post => (
|
||||
<a href={`/post/${post.slug}`}>
|
||||
<article class="post-card">
|
||||
<div class="post-cover">
|
||||
<LazyImage src={post.cover} alt={post.title} />
|
||||
</div>
|
||||
<div class="post-body">
|
||||
<div class="post-meta">
|
||||
|
||||
<a href={`/post/${post.slug}`}>
|
||||
<article class="post-card">
|
||||
<div class="post-cover">
|
||||
<LazyImage src={post.cover} alt={post.title}/>
|
||||
</div>
|
||||
<div class="post-body">
|
||||
<div class="post-meta">
|
||||
<span>
|
||||
<img src={Calendar} alt="Calendar"/>
|
||||
{post.published_at}
|
||||
{published_at}
|
||||
</span>
|
||||
<span>
|
||||
<span>
|
||||
<img src={Folder} alt="Folder"/>
|
||||
{post.category_name}
|
||||
{post.category_name}
|
||||
</span>
|
||||
<span>
|
||||
<span>
|
||||
<img src={Eye} alt="Eye"/>
|
||||
{post.view}
|
||||
{post.view_count}
|
||||
</span>
|
||||
</div>
|
||||
<h3 class="post-title">
|
||||
{post.title}
|
||||
</h3>
|
||||
<div class="post-summary">
|
||||
{post.summary}
|
||||
</div>
|
||||
<div class="tags">
|
||||
{post.tags.map(tag => <div class="tag">{tag.name}</div>)}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</a>
|
||||
))}
|
||||
</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>
|
||||
</div>
|
||||
<h3 class="post-title">
|
||||
{post.title}
|
||||
</h3>
|
||||
<div class="post-summary">
|
||||
{post.summary}
|
||||
</div>
|
||||
<div class="tags">
|
||||
{post.tags.map(tag =>
|
||||
<div class="tag">{tag.name}</div>)}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</a>
|
||||
|
||||
<style>
|
||||
.section {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.post-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
@@ -175,46 +141,8 @@ posts.map((post) => {
|
||||
background: var(--tag-hover-bg);
|
||||
}
|
||||
|
||||
/* ========== 分页 ========== */
|
||||
.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;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.post-list{
|
||||
.post-list {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
@@ -232,7 +160,7 @@ posts.map((post) => {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.post-meta{
|
||||
.post-meta {
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -248,7 +176,7 @@ posts.map((post) => {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.post-meta{
|
||||
.post-meta {
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -258,10 +186,9 @@ posts.map((post) => {
|
||||
height: 62px;
|
||||
}
|
||||
|
||||
.post-summary{
|
||||
.post-summary {
|
||||
font-size: 12px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
31
src/components/Post/List.astro
Normal file
31
src/components/Post/List.astro
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
import type {Post} from "@/types/post";
|
||||
import PostItem from '@/components/Post/Item.astro'
|
||||
|
||||
interface Props {
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
const {posts} = Astro.props
|
||||
---
|
||||
|
||||
<section class="section">
|
||||
<div class="post-list">
|
||||
{posts.map(post => (
|
||||
<PostItem post={post}/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.section {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
</style>
|
||||
60
src/components/Post/Pagination.astro
Normal file
60
src/components/Post/Pagination.astro
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
interface Props {
|
||||
page: number
|
||||
totalPage: number
|
||||
}
|
||||
|
||||
const {page, totalPage} = Astro.props
|
||||
---
|
||||
|
||||
<!--分页器-->
|
||||
{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>}
|
||||
|
||||
<style>
|
||||
/* ========== 分页 ========== */
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user