-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(v2): blog slug frontmatter #3284
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 76073b8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me, but I'd rather not format the slug provided by the user: he's responsible to provide a valid one (like for docs).
Also, can you add more tests?
I'd like to see tests related to slugs, with different kind of slugs (with/without leading /, with/without special chars etc).
If something is easy to test, it should rather be tested. I'm not a regexp expert, intuitively I don't know what formatSlug does exactly, but tests would tell me by examples.
routeBasePath, | ||
frontMatter.id || toUrl({date, link: linkName}), | ||
]), | ||
permalink: normalizeUrl([baseUrl, routeBasePath, formatSlug(slug)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'd be more comfortable if you did not format the slug if it's provided by frontmatter.
The docs plugin does not do any normalization either so I prefer it to be consistent.
The user should be able to use slug: /hey/my super path/héllô
and it should work
Thanks :) tested and it works fine |
Motivation
Solving the slug issue raised in issue #3230
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
The code changes affected the interaction with blog post url slugs.
They now operate in the following manner:
slug
option is not passed:YYYY-MM-DD-blog-name.md
, the blog will be accessible at/blog/YYYY/MM/DD/blog-name
test-blog.md
, is accessible at/blog/test-blog
slug
option is passed, the slug takes that value. Exampleslug: 2020/08/14/test-blog
will be accessible at/blog/2020/08/14/test-blog
These changes and different situations were tested manually by using
yarn test:build:v2
which deployed the packages to a local verdaccio server, and created a test-website docusaurus project where I could run different blog post slug tests.Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)