feat(theme-classic): new DocLink component
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 #0000) and the maintainers have approved on my working plan.
Motivation
This is related to #7402 to implement the <DocLink> component. I would like a way to link to docs from non-doc pages and with the custom versioning we have set up (not using current as our docs base url) then I had to use import { useLatestVersion } from "@docusaurus/plugin-content-docs/client"; as @Josh-Cena suggested.
I am admittedly very green to development within Docusaurus and React in general, so please feel free to give me guidance on any changes needed. Figured it would be better to get this minimal bit out there and get feedback than struggling to make it "perfect" myself ;)
Test Plan
I have added a (admittedly minimal) test to the Docusaurus website for the "v1 to v2 migration guide" link.
Also added a this to the latest blog post page in the theming section (swizzling link):
Test links
Deploy preview: https://deploy-preview-7943--docusaurus-2.netlify.app Test on blog post: https://deploy-preview-7943--docusaurus-2.netlify.app/blog/2022/08/01/announcing-docusaurus-2.0/#theming (swizzling bullet point under theming)
Related issues/PRs
https://github.com/facebook/docusaurus/issues/7402
Additional Items
- [x] If there's a way to dynamically get the doc title (I'm thinking the H1 and not the sidebar label) then it would be nice to be able to automatically retrieve it
- [ ] Doesn't respect if anything other than
erroris used foronBrokenLinksinceuseLayoutDocthrows an error and will only ignore if the doc is marked as a draft. Could also look at having a separate function since it seemsuseLayoutDocis meant exclusively for generating navbar-type links (which should throw an error if broken I guess)
[V2]
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | d8a8d06dbc94d716a370b992a665fb96761a1b73 |
| Latest deploy log | https://app.netlify.com/sites/docusaurus-2/deploys/62f55c551a8f3300095c27b1 |
| Deploy Preview | https://deploy-preview-7943--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 settings.
⚡️ Lighthouse report for the deploy preview of this PR
| URL | Performance | Accessibility | Best Practices | SEO | PWA | Report |
|---|---|---|---|---|---|---|
| / | 🟢 91 | 🟢 98 | 🟢 100 | 🟢 100 | 🟠 80 | Report |
| /docs/installation | 🟠 75 | 🟢 100 | 🟢 100 | 🟢 100 | 🟢 90 | Report |
Converting this one to a draft for now. I have a few questions to help iron out a few areas:
- In the current implementation I've added
titletoGlobalDoc. I could also see a potential to add something likedescription. I'm not sure if this is the correct place to put this type of data. If it is, then I can work on adjusting the tests for global data that are causing issues now - I'm currently using
useLayoutDocto get the path of the doc based on ID, but that throws an error if it doesn't exist regardless of the onBrokenLink settings in the config. I can see why this behaviour would want to be retained for navbar so should a function similar touseLayoutDocbe created (or a wrapper) that will more "gracefully" check the config? - I added a usage of this to the blog post but that adds a dependency to docs within the blog plugin (user dependency, not a framework dependency if that makes sense). I feel like what I added is a valid use case but would appreciate feedback as I think it would affect CI.