Add draft field to each post

This commit is contained in:
Maciej Pędzich 2023-05-10 22:53:51 +02:00
parent 8af70859e3
commit a1e0c32d02
4 changed files with 31 additions and 36 deletions

View File

@ -22,6 +22,11 @@
"default": "{{now}}", "default": "{{now}}",
"isPublishDate": true "isPublishDate": true
}, },
{
"title": "Draft",
"name": "draft",
"type": "draft"
},
{ {
"title": "Categories", "title": "Categories",
"name": "categories", "name": "categories",

View File

@ -7,6 +7,7 @@ categories:
tags: tags:
- vue - vue
- nuxt - nuxt
draft: false
--- ---
## Introduction ## Introduction

View File

@ -4,6 +4,7 @@ const blog = defineCollection({
schema: z.object({ schema: z.object({
title: z.string(), title: z.string(),
description: z.string(), description: z.string(),
draft: z.boolean(),
pubDate: z pubDate: z
.string() .string()
.or(z.date()) .or(z.date())

View File

@ -1,44 +1,32 @@
--- ---
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
import BaseHead from '../../components/BaseHead.astro'; const posts = (await getCollection('blog', (entry) => !entry.data.draft)).sort(
import Header from '../../components/Header.astro';
import Footer from '../../components/Footer.astro';
const posts = (await getCollection('blog')).sort(
(a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf() (a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()
); );
--- ---
<!DOCTYPE html> <BaseLayout
<html lang="en"> title="blog"
<head> description="blog about the making of maciej's projects and more"
<BaseHead >
title="blog" <section>
description="blog about the making of maciej's projects and more" <h2>My blog</h2>
/> <ul class="post-list">
<style> {
section { posts.map((post) => (
text-align: center; <li>
<a href={`/blog/${post.slug}/`}>{post.data.title}</a>
</li>
))
} }
</style> </ul>
</head> </section>
<body> </BaseLayout>
<Header />
<main> <style>
<section> section {
<h2>My blog</h2> text-align: center;
<ul class="post-list"> }
{ </style>
posts.map((post) => (
<li>
<a href={`/blog/${post.slug}/`}>{post.data.title}</a>
</li>
))
}
</ul>
</section>
</main>
<Footer />
</body>
</html>