Display draft posts in development mode only

This commit is contained in:
2023-12-01 21:14:27 -06:00
parent e0fe3067c7
commit b1e4f1a583
3 changed files with 17 additions and 12 deletions

View File

@@ -2,7 +2,7 @@
import { getCollection } from "astro:content";
import General from "@layouts/General.astro";
import Summary from "@components/Summary.astro";
const posts = (await getCollection("blog")).filter(entry => !entry.data.draft);
const posts = (await getCollection("blog")).filter(entry => import.meta.env.DEV || !entry.data.draft);
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
---

View File

@@ -3,11 +3,10 @@ import Post from "@layouts/Post.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const blogEntries = await getCollection("blog");
return blogEntries
.filter((entry) => !entry.data.draft)
const posts = await getCollection("blog");
return posts
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
.map((entry) => {
console.log(entry.data.title);
return {
params: { slug: entry.slug },
props: { entry },

View File

@@ -1,15 +1,21 @@
---
import General from '@layouts/General.astro';
import { getCollection } from 'astro:content';
import General from "@layouts/General.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
const tags = new Set(blogEntries.filter(entry => !entry.data.draft).map(entry => entry.data.tags).flat());
return Array.from(tags, (tag) => ({ params: {slug: tag}, props: {tag}}));
const blogEntries = await getCollection("blog");
const tags = new Set(
blogEntries
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
.map((entry) => entry.data.tags)
.flat(),
);
return Array.from(tags, (tag) => ({ params: { slug: tag }, props: { tag } }));
}
const { tag } = Astro.props;
---
<General title={`${tag} posts`}>
{ tag }
{tag}
</General>