Skip to content

Commit a22b16a

Browse files
committed
fix: show drafts on preview urls + in dev mode
1 parent 3910c81 commit a22b16a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

modules/blog.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { read } from 'gray-matter'
88
import { safeParse } from 'valibot'
99
import { BlogPostSchema, type BlogPostFrontmatter } from '../shared/schemas/blog'
1010
import { globSync } from 'tinyglobby'
11+
import { isProduction } from '../config/env'
1112

1213
/**
1314
* Scans the blog directory for .md files and extracts validated frontmatter.
@@ -75,13 +76,13 @@ export default defineNuxtModule({
7576
}),
7677
)
7778

78-
// Expose frontmatter for published (non-draft) posts to avoid bundling the
79-
// full content of all posts in the `/blog` listing page.
79+
// Expose frontmatter for the `/blog` listing page.
80+
const showDrafts = nuxt.options.dev || !isProduction
8081
addTemplate({
8182
filename: 'blog/posts.ts',
8283
write: true,
8384
getContents: () => {
84-
const posts = loadBlogPosts(blogDir).filter(p => !p.draft)
85+
const posts = loadBlogPosts(blogDir).filter(p => showDrafts || !p.draft)
8586
return [
8687
`import type { BlogPostFrontmatter } from '#shared/schemas/blog'`,
8788
``,

0 commit comments

Comments
 (0)