docusaurus
docusaurus copied to clipboard
feat(blog): slug/pathname aliases for blog posts
Pre-flight checklist
- [x] I have read the Contributing Guidelines on pull requests.
- [x] If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
- [x] If this is a new API or substantial change: the PR has an accompanying issue (closes #8311) and the maintainers have approved on my working plan.
Motivation
It would be great to have alias URLs for blog posts, so as well as /my-blog-post
you could have /my-other-url-for-blog-post
.
Ideally the canonical link remains pointing to the permalink. HOWEVER I'M NOT SURE HOW BEST TO IMPLEMENT THIS PART
Consider:
https://github.com/facebook/docusaurus/blob/ca3dba5e5eab0f8b8a9b3388e2b2e637fe3a19a7/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx#L58-L65
The canonical URL is driven just by the pathname of the page. There's not an obvious way to provide a canonical URL to this without serious code changes. Rather than do this unsupervised, I wanted to ask if there was an approach that might be good approach to take?
Test Plan
Please see the new tests / amended tests.
Test links
Deploy preview: https://deploy-preview-8356--docusaurus-2.netlify.app/
Related issues/PRs
#8311
[V2]
Built without sensitive environment variables
Name | Link |
---|---|
Latest commit | ab1cf60c8c7757e67b371623341d842c18a0dc44 |
Latest deploy log | https://app.netlify.com/sites/docusaurus-2/deploys/6584653b2298f500087302ce |
Deploy Preview | https://deploy-preview-8356--docusaurus-2.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
⚡️ Lighthouse report for the deploy preview of this PR
URL | Performance | Accessibility | Best Practices | SEO | PWA | Report |
---|---|---|---|---|---|---|
/ | 🟠 73 | 🟢 98 | 🟢 100 | 🟢 100 | 🟠 89 | Report |
/docs/installation | 🟠 68 | 🟢 98 | 🟢 100 | 🟢 100 | 🟠 89 | Report |
/docs/category/getting-started | 🟠 76 | 🟢 100 | 🟢 100 | 🟢 90 | 🟠 89 | Report |
/blog | 🟠 75 | 🟢 100 | 🟢 100 | 🟢 90 | 🟠 89 | Report |
/blog/preparing-your-site-for-docusaurus-v3 | 🟠 61 | 🟢 97 | 🟢 100 | 🟢 100 | 🟠 89 | Report |
/blog/tags/release | 🟠 76 | 🟢 100 | 🟢 100 | 🟠 80 | 🟠 89 | Report |
/blog/tags | 🟠 78 | 🟢 100 | 🟢 100 | 🟢 90 | 🟠 89 | Report |
Thanks for the comments - I'll take a look at them. But before doing I wanted to get your thoughts on the below: (copied from the motivation section up top). Given that this will likely change implementation somewhat, I wanted to tackle that before the code comments. Hope this makes sense!
Motivation
It would be great to have alias URLs for blog posts, so as well as /my-blog-post
you could have /my-other-url-for-blog-post
.
Ideally the canonical link remains pointing to the permalink. HOWEVER I'M NOT SURE HOW BEST TO IMPLEMENT THIS PART
Consider:
https://github.com/facebook/docusaurus/blob/ca3dba5e5eab0f8b8a9b3388e2b2e637fe3a19a7/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx#L58-L65
The canonical URL is driven just by the pathname of the page. There's not an obvious way to provide a canonical URL to this without serious code changes. Rather than do this unsupervised, I wanted to ask if there was an approach that might be good approach to take?
I guess this logic should only be used for as a fallback for pages that do not define an explicit canonical URL (which is likely the case for user-created standalone pages)
If a content-plugin supports the aliasing feature then it probably needs to declare the canonical url deeper in the tree, to override this fallback value.
That probably makes sense to add it to the PageMetadata helper considering it sets 2 meta at once and could be reused in the future
It is ok to declare the same meta multiple times in the tree, Head is supposed to deduplicate it.