Skip to content

Commit 23c3d6a

Browse files
kevinwuhooDimitri POSTOLOVdimaMachina
authored
Support draft/hidden posts (#2049)
* support draft/hidden posts * add changeset --------- Co-authored-by: Dimitri POSTOLOV <[email protected]> Co-authored-by: Dimitri POSTOLOV <[email protected]>
1 parent a1cc984 commit 23c3d6a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.changeset/warm-pens-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra-theme-blog': minor
3+
---
4+
5+
support draft posts via frontMatter's `draft: true` value

examples/blog/pages/posts/draft.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Draft
3+
date: 2023/6/28
4+
description: An example of a draft post.
5+
draft: true
6+
tag: web development
7+
author: Ada Lovelace
8+
---
9+
10+
Because this post has `draft: true` defined in its frontmatter, it won't show up
11+
in the [list of posts](/posts) or
12+
[list of posts by tag](/tags/web%20development) but can be access directly by
13+
its url at [/posts/draft](/posts/draft).

packages/nextra-theme-blog/src/utils/collect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const isPost = (page: PageMapItem): page is MdxFile => {
1414
page.name.startsWith('_')
1515
)
1616
return false
17-
const type = page.frontMatter?.type
18-
return !type || type === 'post'
17+
const { draft, type } = page.frontMatter || {}
18+
return !draft && (!type || type === 'post')
1919
}
2020

2121
export const collectPostsAndNavs = ({ opts }: LayoutProps) => {

0 commit comments

Comments
 (0)