-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Enable managing broken links from a report #11101
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
base: main
Are you sure you want to change the base?
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
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.
Could you reuse the existing onBrokenLinks
and onBrokenAnchors
APIs instead of introducing a new API that conflicts with the existing ones?
The API could be:
const config = {
onBrokenLinks: ({brokenLinks, utils}) => {
const message = utils.createBrokenLinksMessage({brokenLinks})
console.error(message);
}),
onBrokenAnchors: ({brokenAnchors, utils}) => {
const message = utils.createBrokenAnchorsMessage({brokenAnchors})
console.warn(message);
}),
}
Injecting an utils
attribute permits to expose our existing functions to create messages. It's useful because people that want callbacks will usually want to filter the list or other similar operations, and may be less interested in creating a custom message.
Example use case: someone may decide that docs throw on broken links, but blog posts and other pages only warn. They should be able to "split" the list into 2 sublists, and report individual sublists.
const config = {
onBrokenLinks: ({brokenLinks, utils}) => {
const [docsBrokenLinks, otherBrokenLinks] = splitList(brokenLinks);
if (docsBrokenLinks.length) {
throw new Error(utils.createBrokenLinksMessage({brokenLinks: docsBrokenLinks}))
}
if (otherBrokenLinks.length) {
console.warn(otherBrokenLinks);
}
}),
onBrokenAnchors: "throw",
}
This API would give great flexibility for users to do fancy things we didn't think of.
Does it make sense?
I'll be back in a few days to follow up on this PR, until then I hope my review will be helpful.
👋
}: { | ||
collectedLinks: CollectedLinks; | ||
onBrokenLinks: ReportingSeverity; | ||
onBrokenAnchors: ReportingSeverity; | ||
routes: RouteConfig[]; | ||
onReportBrokenLinks?: (brokenLinksMap: BrokenLinksMap) => void; |
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.
I'd prefer to avoid introducing a new API when we already have one
Im on Easter vacations but as soon as i get back i will look into the implementations. |
Pre-flight checklist
Motivation
Since broken links were being generated from various sources like Redocusaurus, we needed a more flexible way to handle them. To solve this, i introduced the
onReportBrokenLinks
function, which allows us to manage each broken link individually based on specific business needs.Usage:
https://deploy-preview-11101--docusaurus-2.netlify.app/docs/api/docusaurus-config#onReportBrokenLinks
Test Plan
When a broken link is detected, we should have the ability to handle it—such as removing it, in this case—before including it in the report.
Test links
Created a Unit Test:
/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts
Deploy preview: https://deploy-preview-11101--docusaurus-2.netlify.app/docs/api/docusaurus-config
Related issues/PRs
#9986