diff --git a/src/content/config.ts b/src/content/config.ts index 4e9eeed..55ff5f7 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -7,6 +7,7 @@ const postCollection = defineCollection({ published: z.date(), updated: z.date().optional(), tags: z.array(z.string()), + draft: z.boolean().optional(), }), }); diff --git a/src/pages/blog/[page].astro b/src/pages/blog/[page].astro index d2c85d9..729f5e2 100644 --- a/src/pages/blog/[page].astro +++ b/src/pages/blog/[page].astro @@ -11,9 +11,11 @@ interface Props { } export const getStaticPaths = (async ({ paginate }) => { - const allPosts = (await getCollection("post")).sort((a, b) => - a.data.published < b.data.published ? 1 : -1, - ); + const allPosts = ( + await getCollection("post", ({ data }) => { + return !(import.meta.env.PROD && data.draft); + }) + ).sort((a, b) => (a.data.published < b.data.published ? 1 : -1)); return paginate(allPosts, { pageSize: 10 }); }) satisfies GetStaticPaths; diff --git a/src/pages/blog/[slug].astro b/src/pages/blog/[slug].astro index cae987e..8cb21a1 100644 --- a/src/pages/blog/[slug].astro +++ b/src/pages/blog/[slug].astro @@ -9,7 +9,9 @@ interface Props { } export const getStaticPaths = (async () => { - const blogs = await getCollection("post"); + const blogs = await getCollection("post", ({ data }) => { + return !(import.meta.env.PROD && data.draft); + }); return blogs.map((post) => ({ params: { slug: post.slug }, diff --git a/src/pages/tag/[tag]/[page].astro b/src/pages/tag/[tag]/[page].astro index c78173a..68d137a 100644 --- a/src/pages/tag/[tag]/[page].astro +++ b/src/pages/tag/[tag]/[page].astro @@ -12,7 +12,9 @@ interface Props { } export const getStaticPaths = (async ({ paginate }) => { - const allPosts = await getCollection("post"); + const allPosts = await getCollection("post", ({ data }) => { + return !(import.meta.env.PROD && data.draft); + }); const uniqueTags = [ ...new Set(allPosts.map((post) => post.data.tags).flat()), ];