Skip to content

Commit

Permalink
Support draft/hidden posts (#2049)
Browse files Browse the repository at this point in the history
* support draft/hidden posts

* add changeset

---------

Co-authored-by: Dimitri POSTOLOV <en3m@ya.ru>
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
3 people authored Aug 13, 2023
1 parent a1cc984 commit 23c3d6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-pens-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra-theme-blog': minor
---

support draft posts via frontMatter's `draft: true` value
13 changes: 13 additions & 0 deletions examples/blog/pages/posts/draft.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Draft
date: 2023/6/28
description: An example of a draft post.
draft: true
tag: web development
author: Ada Lovelace
---

Because this post has `draft: true` defined in its frontmatter, it won't show up
in the [list of posts](/posts) or
[list of posts by tag](/tags/web%20development) but can be access directly by
its url at [/posts/draft](/posts/draft).
4 changes: 2 additions & 2 deletions packages/nextra-theme-blog/src/utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const isPost = (page: PageMapItem): page is MdxFile => {
page.name.startsWith('_')
)
return false
const type = page.frontMatter?.type
return !type || type === 'post'
const { draft, type } = page.frontMatter || {}
return !draft && (!type || type === 'post')
}

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

1 comment on commit 23c3d6a

@vercel
Copy link

@vercel vercel bot commented on 23c3d6a Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.