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