From a1e0c32d02efa34b1832f5d47482ebc86e6bb2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Wed, 10 May 2023 22:53:51 +0200 Subject: [PATCH] Add draft field to each post --- frontmatter.json | 5 +++ src/content/blog/first-post.md | 1 + src/content/config.ts | 1 + src/pages/blog/index.astro | 60 ++++++++++++++-------------------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/frontmatter.json b/frontmatter.json index e66e96c..5d8daee 100644 --- a/frontmatter.json +++ b/frontmatter.json @@ -22,6 +22,11 @@ "default": "{{now}}", "isPublishDate": true }, + { + "title": "Draft", + "name": "draft", + "type": "draft" + }, { "title": "Categories", "name": "categories", diff --git a/src/content/blog/first-post.md b/src/content/blog/first-post.md index c30c525..f72bfc0 100644 --- a/src/content/blog/first-post.md +++ b/src/content/blog/first-post.md @@ -7,6 +7,7 @@ categories: tags: - vue - nuxt +draft: false --- ## Introduction diff --git a/src/content/config.ts b/src/content/config.ts index 8d85e7d..d8b87a2 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -4,6 +4,7 @@ const blog = defineCollection({ schema: z.object({ title: z.string(), description: z.string(), + draft: z.boolean(), pubDate: z .string() .or(z.date()) diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 9e4ebc2..e784797 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,44 +1,32 @@ --- import { getCollection } from 'astro:content'; +import BaseLayout from '../../layouts/BaseLayout.astro'; -import BaseHead from '../../components/BaseHead.astro'; -import Header from '../../components/Header.astro'; -import Footer from '../../components/Footer.astro'; - -const posts = (await getCollection('blog')).sort( +const posts = (await getCollection('blog', (entry) => !entry.data.draft)).sort( (a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf() ); --- - - - - - - - -
-
-
-

My blog

- -
-
-