diff --git a/src/content/posts/_schemas.ts b/src/content/posts/_schemas.ts index a83584c..431b29d 100644 --- a/src/content/posts/_schemas.ts +++ b/src/content/posts/_schemas.ts @@ -4,6 +4,7 @@ import { z, reference } from 'astro:content'; export const posts = ({ image }) => z.object({ title: z.string(), description: z.string().optional(), + draft: z.boolean().optional().default(false), summary: z.string().optional(), date: z.coerce.date(), categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']), diff --git a/src/pages/blog.astro b/src/pages/blog.astro index 3d9cd35..d5e959d 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -9,7 +9,9 @@ import { getLangFromUrl, useTranslations, useTranslatedPath } from '../i18n/util const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); const translatePath = useTranslatedPath(lang); -const posts = await getCollection('posts'); +const posts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime()); --- diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index ff51015..9b14a75 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -17,7 +17,9 @@ const t = useTranslations(lang); const translatePath = useTranslatedPath(lang); export async function getStaticPaths() { - const blogEntries = await getCollection('posts'); + const blogEntries = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); return blogEntries.map(entry => ({ params: { slug: entry.slug }, props: { entry }, })); diff --git a/src/pages/blog/[...slug].txt.js b/src/pages/blog/[...slug].txt.js index 6c90c63..9825e05 100644 --- a/src/pages/blog/[...slug].txt.js +++ b/src/pages/blog/[...slug].txt.js @@ -2,7 +2,9 @@ import { getCollection } from 'astro:content'; export const prerender = true; export async function getStaticPaths() { - const blogEntries = await getCollection('posts'); + const blogEntries = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); return blogEntries.map(entry => ({ params: { slug: entry.slug }, props: { entry }, })); diff --git a/src/pages/blog/[slug]/featured.png.js b/src/pages/blog/[slug]/featured.png.js index 1d43c47..453abfa 100644 --- a/src/pages/blog/[slug]/featured.png.js +++ b/src/pages/blog/[slug]/featured.png.js @@ -62,7 +62,9 @@ const fileCache = { }; export async function getStaticPaths() { - const blogEntries = await getCollection('posts'); + const blogEntries = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); return blogEntries.map(post => ({ params: { slug: post.slug }, props: { post }, })); diff --git a/src/pages/categories.astro b/src/pages/categories.astro index bae76c3..dbe2bd4 100644 --- a/src/pages/categories.astro +++ b/src/pages/categories.astro @@ -1,7 +1,9 @@ --- import {getCollection} from "astro:content"; import Layout from "../layouts/Layout.astro"; -const allPosts = await getCollection('posts'); +const allPosts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories ? post.data.categories : []).flat())]; --- diff --git a/src/pages/categories/[...category].astro b/src/pages/categories/[...category].astro index c1c1b13..3b3a3d4 100644 --- a/src/pages/categories/[...category].astro +++ b/src/pages/categories/[...category].astro @@ -4,7 +4,9 @@ import {getCollection} from "astro:content"; import ArticleList from "../../components/ArticleList.astro"; export async function getStaticPaths() { - const allPosts = await getCollection('posts'); + const allPosts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); // Get all categories, ensuring the default 'uncategorized' is used when categories is undefined const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories || ['uncategorized']).flat())]; diff --git a/src/pages/search-index.json.js b/src/pages/search-index.json.js index 8686b3b..65da20b 100644 --- a/src/pages/search-index.json.js +++ b/src/pages/search-index.json.js @@ -1,7 +1,9 @@ import { getCollection } from 'astro:content'; export async function GET() { - const posts = await getCollection('posts'); + const posts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); const searchIndex = posts.map(post => ({ title: post.data.title, description: post.data.description || '', diff --git a/src/pages/tags.astro b/src/pages/tags.astro index 340f690..3467401 100644 --- a/src/pages/tags.astro +++ b/src/pages/tags.astro @@ -1,7 +1,9 @@ --- import {getCollection} from "astro:content"; import Layout from "../layouts/Layout.astro"; -const allPosts = await getCollection('posts'); +const allPosts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())]; --- diff --git a/src/pages/tags/[...tag].astro b/src/pages/tags/[...tag].astro index 3b74126..865a49a 100644 --- a/src/pages/tags/[...tag].astro +++ b/src/pages/tags/[...tag].astro @@ -4,7 +4,9 @@ import {getCollection} from "astro:content"; import ArticleList from "../../components/ArticleList.astro"; export async function getStaticPaths() { - const allPosts = await getCollection('posts'); + const allPosts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())]; return uniqueTags.map((tag) => { const filteredPosts = allPosts.filter((post: any) => post.data.tags?.includes(tag)); diff --git a/src/pages/twtxt.txt.js b/src/pages/twtxt.txt.js index 6af2c49..9311550 100644 --- a/src/pages/twtxt.txt.js +++ b/src/pages/twtxt.txt.js @@ -1,7 +1,9 @@ import { getCollection } from 'astro:content'; export async function GET(context) { - const posts = await getCollection('posts'); + const posts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); // Sort posts by date (newest first) posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime()); diff --git a/src/plugins/heatmapdata/local.js b/src/plugins/heatmapdata/local.js index 0c04586..470a3c7 100644 --- a/src/plugins/heatmapdata/local.js +++ b/src/plugins/heatmapdata/local.js @@ -1,7 +1,9 @@ import { getCollection, render } from 'astro:content'; async function fetchPostsData() { - const posts = await getCollection('posts'); + const posts = await getCollection('posts', ({ data }) => { + return import.meta.env.PROD ? data.draft !== true : true; +}); const entriesData = {}; for (const post of posts) {