diff --git a/src/components/header/HeaderNavigation.tsx b/src/components/header/HeaderNavigation.tsx index 079f728..dd09c96 100644 --- a/src/components/header/HeaderNavigation.tsx +++ b/src/components/header/HeaderNavigation.tsx @@ -9,7 +9,7 @@ export default function App() { const menuItems = [ { link: "/archive", - name: "目录", + name: "博客", }, { link: "/calendar", diff --git a/src/pages/archive.astro b/src/pages/archive.astro index 61d9d24..51c76c5 100644 --- a/src/pages/archive.astro +++ b/src/pages/archive.astro @@ -1,43 +1,89 @@ --- import BaseLayout from "../layouts/BaseLayout.astro" -import ArchivePostList from "../layouts/ArchivePostList.astro" -const allPosts = await Astro.glob("./posts/*.md") -const Blogs = await Astro.glob("../pages/posts/blogs/**/*.md") -const tags = ["寝室", "技术", "学习", "活动", "其他"] -const posts = [] +import type { MarkdownInstance } from "astro" +import dayjs from "dayjs" -tags.forEach((tag) => { - const filteredPosts = allPosts.filter(post => - post.frontmatter.tags.includes(tag), - ) - const filteredBlogs = Blogs.filter( - post => post.frontmatter.tags?.includes(tag) ?? tag === "其他", - ) - posts.push([...filteredPosts, ...filteredBlogs]) +type Cover = { + url: string + square: string + alt: string +} | string + +type Post = { + layout: string + title: string + pubDate: string // ISO 字符串,可选改为 `Date` 类型 + description: string + author: string + cover?: Cover + tags: string[] + theme: string + featured: boolean +} + +const posts: MarkdownInstance[] = await Astro.glob("./posts/*.md") +const blogs: MarkdownInstance[] = await Astro.glob("../pages/posts/blogs/**/*.md") + +const allPosts = [...posts, ...blogs].sort((a, b) => { + return new Date(b.frontmatter.pubDate).getTime() - new Date(a.frontmatter.pubDate).getTime() }) + +const getCover = (post: MarkdownInstance) => { + if (typeof post.frontmatter.cover === "string") { + return { url: post.frontmatter.cover, square: post.frontmatter.cover, alt: "" } + } + return post.frontmatter.cover || { url: "", square: "", alt: "" } +} + + // const tags = allPosts.reduce((acc, post) => { + // post.frontmatter.tags.forEach(tag => { + // if (!acc.includes(tag)) { + // acc.push(tag) + // } + // }) + // return acc + // }, [] as string[]).sort((a, b) => a.localeCompare(b)) + --- - -
-
-
+ + +
+ +
+