docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

feat(mdx-loader): Remark plugin to report unused MDX / Markdown anchors links

Open OzakIOne opened this issue 2 years ago • 2 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.
  • [ ] If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

As of today, Docusaurus only check broken links and numerous people would like Docusaurus to check broken anchors.

I've made a PoC remark plugin that aims to detect broken anchors and warn the user about it, so far here is the functionality implemented :

  • [x] Detect broken anchors in the same file
  • [ ] Detect broken anchors in an other file
  • [ ] Detect broken anchors of headings having a custom id # Title {#custom-id}
  • [ ] Support mdx files with react pages

For the custom id it should be fairly easy to support it, the problem is just that in the jest tests the remark plugin for custom id doesn't seems to work, and implement the custom id in the rendered html, it just renders it as text

For the broken anchors related to an other .md file, I don't know how to implement it, I thought we could do it in this remark plugin by recursively checking .md files and checking the anchors however it doesn't seems to be the right way to do it.

For now the only way for users to check the anchors in other files is to setup a ci with remark validate links

Test Plan

Test links

yarn jest brokenAnchors --watch

Deploy preview: https://deploy-preview-9512--docusaurus-2.netlify.app/

Related issues/PRs

https://github.com/facebook/docusaurus/issues/3321

OzakIOne avatar Nov 07 '23 13:11 OzakIOne

[V2]

Built without sensitive environment variables

Name Link
Latest commit 15101cdcd31986d379b8b640ec4b1fbf9f0f4ebe
Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/654a3ebc46cdea000872fe7d
Deploy Preview https://deploy-preview-9512--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 07 '23 13:11 netlify[bot]

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 58 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/installation 🟠 74 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/category/getting-started 🟠 67 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog 🟠 60 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 51 🟢 97 🟢 100 🟢 100 🟠 89 Report
/blog/tags/release 🟠 61 🟢 100 🟢 100 🟠 80 🟠 89 Report
/blog/tags 🟠 60 🟢 100 🟢 100 🟢 90 🟠 89 Report

github-actions[bot] avatar Nov 07 '23 13:11 github-actions[bot]