docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

feat(blog): slug/pathname aliases for blog posts

Open johnnyreilly opened this issue 1 year ago • 4 comments

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

johnnyreilly avatar Nov 20 '22 17:11 johnnyreilly

[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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Nov 20 '22 17:11 netlify[bot]

⚡️ 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

github-actions[bot] avatar Nov 20 '22 17:11 github-actions[bot]

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?

johnnyreilly avatar Nov 24 '22 12:11 johnnyreilly

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

CleanShot 2022-12-08 at 18 02 38@2x

It is ok to declare the same meta multiple times in the tree, Head is supposed to deduplicate it.

slorber avatar Dec 08 '22 17:12 slorber