Repository navigation
feat: add "unlisted" front matter option for blog posts - #1396
Conversation
|
Deploy preview for docusaurus-2 ready! Built with commit 031c2cb |
|
Deploy preview for docusaurus-preview ready! Built with commit 031c2cb |
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. --- ```
27f22c2 to
26aee90
Compare
| const Container = require('./Container.js'); | ||
| const MetadataBlog = require('./MetadataBlog.js'); | ||
|
|
||
| const MetadataPublicBlog = MetadataBlog.filter(item => item.unlisted !== true); |
There was a problem hiding this comment.
Where would be a good place to put this shared logic between BlogSidebar.js, BlogPageLayout.js and feed.js?
| const Container = require('./Container.js'); | ||
| const MetadataBlog = require('./MetadataBlog.js'); | ||
|
|
||
| const MetadataPublicBlog = MetadataBlog.filter(item => item.unlisted !== true); |
There was a problem hiding this comment.
| const MetadataPublicBlog = MetadataBlog.filter(item => item.unlisted !== true); | |
| const MetadataPublicBlog = MetadataBlog.filter(item => !item.unlisted); |
yangshun
left a comment
There was a problem hiding this comment.
The change looks good in general, but I'd like to suggest that draft: true could be a better naming than unlisted: true. Jekyll calls them drafts too.
Is there currently a way for you to view your unlisted/draft posts without toggling the flag?
In v2 we should definitely support this feature and allow a command line flag or config option on whether to display them during development.
| readMetadata.generateMetadataBlog(); | ||
| const MetadataBlog = require('../core/MetadataBlog.js'); | ||
| const MetadataPublicBlog = MetadataBlog.filter( | ||
| item => item.unlisted !== true, |
|
Thank you for the review! I've renamed "unlisted" into "draft" and incorporated the
Not in the current implementation. It would be nice to see draft posts during livereload development but I'm not sure how to implement that. |
|
About unlisted vs draft. The way I would expect "draft" to behave is not to make the post public, whereas unlisted would be published but not listed in the menu. To summarize
For this reason, I think 'unlisted' was the appropriate name for the changes included in this PR. |
|
Anything I can do to help unblock this issue? All of the review comments from #1396 (review) have been addressed, although I believe it's worth considering using |
yangshun
left a comment
There was a problem hiding this comment.
@olafurpg Sorry for the late reply. @gabro's comment convinced me that unlisted sounds more appropriate although I'm not leaning strongly towards any particular term. Medium is essentially doing something similar. I'll merge this and make the changes myself since I was the one who asked for the bad change 😅
unlisted header option for blog posts, fixes #1393.unlisted header option for blog posts
unlisted header option for blog posts* Add `unlisted` header option for blog posts, fixes meta#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".
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: trueheader option.Fixes #1393.
Motivation
The motivation for this feature is to make it possible to change dates of published posts without breaking the old URL (which might be widely shared).
Concrete example, we published a blog post two weeks ago that is dated for 2020 (https://scalameta.org/metals/blog/2020/04/12/mercury.html). We have closed three PRs fixing the date (scalameta/metals#683, scalameta/metals#670, scalameta/metals#656) but they have all been closed because changing the date of the post would turn the old URL into a 404.
With the ability to unlist posts, I could unlist the 2020 post, create a new posts dated in 2019 and update the unlisted 2020 post to forward to the new 2019 post.
I'm open for alternative solutions to fix that particular problem. I think unlisting is a flexible solution that could be useful in other situations as well, for example when writing a draft post.
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
I would appreciate help for testing this change since I'm unfamiliar with jest (and JavaScript in general 😅 ). I created a blog post in
__test__/__fixtures__usingunlisted: trueand ranyarn testand everything passed but I expected some snapshot tests to fail.I tested the change manually on our website and it seems to work as expected:
Observe that uncommenting
unlisted: truemakes the post disappear from both the sidebar and the list of all blog posts while the post is still published under the unchanged URL.Related PRs
I'm not aware of any.