feat: add "unlisted" front matter option for blog posts (#1396)

* Add `unlisted` header option for blog posts, fixes #1393.

Previously, the blog sidebar listed the most recent blog posts sorted by
their publish date. This commit adds the ability to hide a specific blog
post from the sidebar and the feed of all blog posts by adding the
`unlisted: true` header option.

```md
title: My Draft Post
unlisted: true # Hide from blog sidebar and main blog page feed.
---
```

* Rename "unlisted" into "draft".
This commit is contained in:
Ólafur Páll Geirsson 2019-06-15 18:24:15 +02:00 committed by Yangshun Tay
parent 60f9228d67
commit da3c91373e
4 changed files with 30 additions and 19 deletions

View file

@ -10,6 +10,8 @@ const BlogPost = require('./BlogPost.js');
const BlogSidebar = require('./BlogSidebar.js');
const Container = require('./Container.js');
const MetadataBlog = require('./MetadataBlog.js');
const MetadataPublicBlog = MetadataBlog.filter(item => !item.draft);
const Site = require('./Site.js');
const utils = require('./utils.js');
@ -40,27 +42,28 @@ class BlogPageLayout extends React.Component {
/>
<Container className="mainContainer postContainer blogContainer">
<div className="posts">
{MetadataBlog.slice(page * perPage, (page + 1) * perPage).map(
post => (
<BlogPost
post={post}
content={post.content}
truncate
key={
utils.getPath(post.path, this.props.config.cleanUrl) +
post.title
}
config={this.props.config}
/>
),
)}
{MetadataPublicBlog.slice(
page * perPage,
(page + 1) * perPage,
).map(post => (
<BlogPost
post={post}
content={post.content}
truncate
key={
utils.getPath(post.path, this.props.config.cleanUrl) +
post.title
}
config={this.props.config}
/>
))}
<div className="docs-prevnext">
{page > 0 && (
<a className="docs-prev" href={this.getPageURL(page - 1)}>
Prev
</a>
)}
{MetadataBlog.length > (page + 1) * perPage && (
{MetadataPublicBlog.length > (page + 1) * perPage && (
<a className="docs-next" href={this.getPageURL(page + 1)}>
Next
</a>