mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:01:42 +08:00
fix: disable access to draft posts via url
This commit is contained in:
@@ -30,7 +30,9 @@ type PagePaths = {
|
|||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
||||||
|
|
||||||
let postResult: PostResult = posts.map(post => {
|
const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft);
|
||||||
|
|
||||||
|
let postResult: PostResult = filteredPosts.map(post => {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
slug: slugify(post.frontmatter),
|
slug: slugify(post.frontmatter),
|
||||||
@@ -41,9 +43,11 @@ export async function getStaticPaths() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const pagePaths: PagePaths = getPageNumbers(posts.length).map(pageNum => ({
|
const pagePaths: PagePaths = getPageNumbers(filteredPosts.length).map(
|
||||||
params: { slug: String(pageNum) },
|
pageNum => ({
|
||||||
}));
|
params: { slug: String(pageNum) },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return [...postResult, ...pagePaths];
|
return [...postResult, ...pagePaths];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user