Skip to content

Commit d031694

Browse files
committed
⚡️ support for draft/in-progress posts
1 parent dacd5b0 commit d031694

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

astro.config.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import mdx from "@astrojs/mdx";
22
import react from "@astrojs/react";
33
import sitemap from "@astrojs/sitemap";
44
import tailwind from "@astrojs/tailwind";
5+
import vercel from "@astrojs/vercel/static";
56
import { defineConfig } from "astro/config";
6-
import vercel from '@astrojs/vercel/static';
77

88
// https://astro.build/config
99
export default defineConfig({
1010
site: "https://appclubosu.vercel.app",
1111
integrations: [
1212
mdx({
13-
syntaxHighlight: 'shiki',
14-
shikiConfig: { theme: 'github-dark-dimmed' },
13+
syntaxHighlight: "shiki",
14+
shikiConfig: { theme: "github-dark-dimmed" },
1515
gfm: true,
1616
}),
1717
sitemap(),

src/content/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const blog = defineCollection({
55
schema: z.object({
66
title: z.string(),
77
description: z.string(),
8+
draft: z.optional(z.boolean()),
89
coverImage: z.string(),
910
category: z.string(),
1011
// Transform string to Date object
@@ -39,5 +40,4 @@ const guides = defineCollection({
3940
}),
4041
});
4142

42-
43-
export const collections = { blog , docs, guides };
43+
export const collections = { blog, docs, guides };

src/lib/fetchers.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { getCollection } from "astro:content";
33
export async function getCategories() {
44
const posts = await getCollection("blog");
55

6-
const categories = [
7-
...new Set([].concat.apply(posts.map((post) => post.data.category))),
8-
];
6+
const categories = posts
7+
.filter((post) => !post.data.draft)
8+
.map((post) => post.data.category)
9+
.filter((category, index, self) => self.indexOf(category) === index);
910

1011
return categories;
1112
}
@@ -14,16 +15,15 @@ export async function getPosts() {
1415
const posts = (await getCollection("blog")).sort(
1516
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
1617
);
17-
18-
return posts;
18+
return posts.filter((post) => !post.data.draft);
1919
}
2020

2121
export async function getPostsByCategory(category: string) {
2222
const posts = (await getCollection("blog"))
2323
.filter((post) => post.data.category === category)
2424
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
2525

26-
return posts;
26+
return posts.filter((post) => !post.data.draft);
2727
}
2828

2929
export async function getGuides() {

0 commit comments

Comments
 (0)