forked from hust-open-atom-club/TranslateProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
import type { CollectionEntry } from "astro:content"; | ||
import Layout from "@layouts/Layout.astro"; | ||
import Main from "@layouts/Main.astro"; | ||
import Pagination from "@components/Pagination.astro"; | ||
import Card from "@components/Card"; | ||
import { SITE } from "@config"; | ||
import { getCollection } from "astro:content"; | ||
export interface Props { | ||
currentPage: number; | ||
totalPages: number; | ||
paginatedPosts: CollectionEntry<"posts">[]; | ||
status: string | undefined; | ||
publishPage?: boolean; | ||
} | ||
// 仅获取状态为"translating"的文章 | ||
const status = "translating"; | ||
const collection = await getCollection( | ||
"posts", | ||
entry => entry.data.status === "translating" | ||
); | ||
const { currentPage, totalPages, publishPage } = Astro.props; | ||
const paginatedPosts = collection; // 假设collection.results包含了分页后的文章列表 | ||
--- | ||
|
||
<Layout title={`${SITE.title}`}> | ||
<!-- <Header activeNav={publishPage ? "posts" : "tasks"} /> --> | ||
<Main pageTitle=""> | ||
<ul> | ||
{ | ||
// sort by date | ||
paginatedPosts | ||
.sort((a, b) => { | ||
// 假设 published_date 是字符串形式如 '20240428' | ||
const dateA = parseInt(a.data.published_date.toString()); | ||
const dateB = parseInt(b.data.published_date.toString()); | ||
return dateB - dateA; // 降序排列,若需升序改为 dateA - dateB | ||
}) | ||
.map(({ id, data, slug, body }) => ( | ||
<Card | ||
id={id} | ||
href={`/posts/${slug}/`} | ||
frontmatter={data} | ||
body={body} | ||
publishCard={publishPage} | ||
/> | ||
)) | ||
} | ||
</ul> | ||
</Main> | ||
|
||
<Pagination | ||
{...{ currentPage, totalPages }} | ||
prevUrl={`/${status}${currentPage - 1 !== 1 ? "/" + (currentPage - 1) : ""}/`} | ||
nextUrl={`/${status}/${currentPage + 1}/`} | ||
/> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters