From f94806bb1dfbe636512fbe92e3920dc2a2b21164 Mon Sep 17 00:00:00 2001 From: linguantao2024 Date: Wed, 17 Jul 2024 12:41:36 +0800 Subject: [PATCH] feat(admin):add admin page and add rank --- pages/src/pages/admin.astro | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pages/src/pages/admin.astro diff --git a/pages/src/pages/admin.astro b/pages/src/pages/admin.astro new file mode 100644 index 0000000..a31f705 --- /dev/null +++ b/pages/src/pages/admin.astro @@ -0,0 +1,73 @@ +--- +import type { CollectionEntry } from "astro:content"; +import Layout from "@layouts/Layout.astro"; +import Main from "@layouts/Main.astro"; +import Header from "@components/Header.astro"; +import Footer from "@components/Footer.astro"; +import Pagination from "@components/Pagination.astro"; +import Card from "@components/Card"; +import { SITE, STATUS_LIST } from "@config"; +import LinkButton from "@components/LinkButton.astro"; +import StatusChart from "@components/StatusChart"; +import getStatusCount from "@utils/getStatusCount"; +import { getCollection } from "astro:content"; + +const countData = getStatusCount(await getCollection("posts")); +async function getAvatar(name: string) { + let avatar = "https://github.com/identicons/" + name + ".png"; // random default avatar https://github.com/identicons/${name}.png + const response = await fetch(`https://api.github.com/search/users?q=${name}`); + const data = await response.json(); + if (data.hasOwnProperty("items") && data.items.length > 0) { + avatar = data.items[0].avatar_url; + } + return avatar; +} + +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 { currentPage, totalPages, paginatedPosts=[] } = Astro.props; + +const status = Astro.props.status || "translating"; + + + + +// 获取所有状态为status的文章 +const postsByStatus = paginatedPosts.filter(post => post.status === status); + +// 获取每篇文章的翻译者和翻译开始时间 +const postsData = await Promise.all(postsByStatus.map(async post => { + const translator = post.translator; + const startTime = post.startTime; + const avatar = await getAvatar(translator); + const deadline = new Date(startTime); + deadline.setMonth(deadline.getMonth() + 1); // 翻译开始时间加一个月 + return { ...post, avatar, startTime, deadline }; +})); +--- + + +
+
+ + + +
    + { + paginatedPosts.map(({ id, data, slug, body }) => ( + + )) + + } +
+
+ + + +