Skip to content

Commit

Permalink
feat(admin):add translating posts
Browse files Browse the repository at this point in the history
  • Loading branch information
moyigeek committed Jul 17, 2024
1 parent 62005e6 commit c39306c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pages/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
63 changes: 63 additions & 0 deletions pages/src/layouts/translating.astro
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>
21 changes: 13 additions & 8 deletions pages/src/pages/admin.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ import { SITE } from "@config";
import StatusChart from "@components/StatusChart";
import getStatusCount from "@utils/getStatusCount";
import { getCollection } from "astro:content";
import Translating from "@layouts/translating.astro";
// import type { Code } from "astro:components";
import getPagination from "@utils/getPagination";
const collection = await getCollection("posts");
const countData = getStatusCount(collection);
// function getStyle(tabStatus: string) {
// const base = "mr-4 select-none inline-block w-20 text-center px-4 py-2 ";
// return tabStatus === status
// ? base + " bg-skin-accent text-skin-inverted hover:text-skin-inverted"
// : base;
// }
const status="translating";
const { totalPages, paginatedPosts = [] } = Astro.props;
// 获取所有状态为status的文章
const trasnlatingPosts = await getCollection("posts", (entry) => entry.data.status === "translating");
const pagination = getPagination({
posts: trasnlatingPosts,
page: 1,
isIndex: true,
});
// 获取每篇文章的翻译者和翻译开始时间
---
Expand Down Expand Up @@ -59,7 +63,8 @@ const { totalPages, paginatedPosts = [] } = Astro.props;
)
}
</ul>
<Translating {...pagination} status={status}/>
</Main>

<Footer noMarginTop={totalPages > 1} />
</Layout>

0 comments on commit c39306c

Please sign in to comment.