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}}",
"isPublishDate": true
},
{
"title": "Draft",
"name": "draft",
"type": "draft"
},
{
"title": "Categories",
"name": "categories",

View File

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

View File

@ -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())

View File

@ -1,31 +1,16 @@
---
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()
);
---
<!DOCTYPE html>
<html lang="en">
<head>
<BaseHead
<BaseLayout
title="blog"
description="blog about the making of maciej's projects and more"
/>
<style>
section {
text-align: center;
}
</style>
</head>
<body>
<Header />
<main>
>
<section>
<h2>My blog</h2>
<ul class="post-list">
@ -38,7 +23,10 @@ const posts = (await getCollection('blog')).sort(
}
</ul>
</section>
</main>
<Footer />
</body>
</html>
</BaseLayout>
<style>
section {
text-align: center;
}
</style>