Skip to content

Commit

Permalink
Merge pull request #40 from K-tecchan/feat/post-draft
Browse files Browse the repository at this point in the history
draft状態の記事をあげないようにした
  • Loading branch information
K-tecchan authored Jul 12, 2024
2 parents b56c778 + cc42d77 commit c660362
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const postCollection = defineCollection({
published: z.date(),
updated: z.date().optional(),
tags: z.array(z.string()),
draft: z.boolean().optional(),
}),
});

Expand Down
8 changes: 5 additions & 3 deletions src/pages/blog/[page].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/pages/blog/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
4 changes: 3 additions & 1 deletion src/pages/tag/[tag]/[page].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
Expand Down

0 comments on commit c660362

Please sign in to comment.