mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: update for new content collection api
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import { CollectionEntry, getCollection } from "astro:content";
|
||||
import Posts from "@layouts/Posts.astro";
|
||||
import PostDetails from "@layouts/PostDetails.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import getPageNumbers from "@utils/getPageNumbers";
|
||||
import type { MarkdownInstance } from "astro";
|
||||
import type { Frontmatter } from "src/types";
|
||||
import slugify from "@utils/slugify";
|
||||
import { SITE } from "@config";
|
||||
|
||||
export interface Props {
|
||||
post: MarkdownInstance<Frontmatter>;
|
||||
post: CollectionEntry<"blog">;
|
||||
}
|
||||
|
||||
type PostResult = {
|
||||
@@ -17,7 +16,7 @@ type PostResult = {
|
||||
slug: string | number;
|
||||
};
|
||||
props?: {
|
||||
post: MarkdownInstance<Record<string, any>>;
|
||||
post: CollectionEntry<"blog">;
|
||||
};
|
||||
}[];
|
||||
|
||||
@@ -28,14 +27,14 @@ type PagePaths = {
|
||||
}[];
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
||||
const posts = await getCollection("blog");
|
||||
|
||||
const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft);
|
||||
const filteredPosts = posts.filter(({ data }) => !data.draft);
|
||||
|
||||
let postResult: PostResult = filteredPosts.map(post => {
|
||||
return {
|
||||
params: {
|
||||
slug: slugify(post.frontmatter),
|
||||
slug: slugify(post.data),
|
||||
},
|
||||
props: {
|
||||
post,
|
||||
@@ -55,7 +54,7 @@ export async function getStaticPaths() {
|
||||
const { slug } = Astro.params;
|
||||
const { post } = Astro.props;
|
||||
|
||||
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
||||
const posts = await getCollection("blog");
|
||||
|
||||
const sortedPosts = getSortedPosts(posts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user