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 { getCollection } from "astro:content";
import General from "@layouts/General.astro"; import General from "@layouts/General.astro";
import Summary from "@components/Summary.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()); 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"; import { getCollection } from "astro:content";
export async function getStaticPaths() { export async function getStaticPaths() {
const blogEntries = await getCollection("blog"); const posts = await getCollection("blog");
return blogEntries return posts
.filter((entry) => !entry.data.draft) .filter((entry) => import.meta.env.DEV || !entry.data.draft)
.map((entry) => { .map((entry) => {
console.log(entry.data.title);
return { return {
params: { slug: entry.slug }, params: { slug: entry.slug },
props: { entry }, props: { entry },

View File

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