add draft notice to post list and fix draft-hiding logic

This commit is contained in:
2026-04-05 06:32:27 -04:00
parent 675ef1003d
commit e0af57e5b1
2 changed files with 18 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
--- ---
title: Example after post title: Example after post
date: 2026-02-28 date: 2026-02-28
draft: true
--- ---
## After ## After

View File

@@ -4,8 +4,8 @@ import '@styles/prose.css';
import { getCollection, render } from 'astro:content'; import { getCollection, render } from 'astro:content';
import BaseLayout from '@layouts/BaseLayout.astro'; import BaseLayout from '@layouts/BaseLayout.astro';
// return all posts // return all posts in dev, only non-draft in prod
let entries = await getCollection('posts', ({ data }) => !data.draft || import.meta.env.PROD ); let entries = await getCollection('posts', ({ data }) => !data.draft || import.meta.env.DEV );
entries.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()); entries.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
const posts = await Promise.all(entries.map(async entry => { const posts = await Promise.all(entries.map(async entry => {
const { remarkPluginFrontmatter } = await render(entry); const { remarkPluginFrontmatter } = await render(entry);
@@ -24,6 +24,7 @@ const posts = await Promise.all(entries.map(async entry => {
<a href={`/${p.id}`} data-astro-prefetch> <a href={`/${p.id}`} data-astro-prefetch>
{p.data.title} {p.data.title}
</a> </a>
{p.data.draft && <span class="draft-notice">Draft</span>}
</h2> </h2>
<p> <p>
{p.remarkPluginFrontmatter.description} {p.remarkPluginFrontmatter.description}
@@ -55,6 +56,20 @@ const posts = await Promise.all(entries.map(async entry => {
margin-left: 0; margin-left: 0;
} }
h2 {
display: flex;
gap: 01rem;
align-items: center;
}
.draft-notice {
font-size: 0.5em;
font-family: 'Figtree Variable', sans-serif;
background-color: var(--accent-color);
padding: 0.05em 0.5em;
border-radius: 20% / 50%;
}
hr { hr {
border: none; border: none;
height: 1px; height: 1px;