The BrokenLinksPlugin will identify any broken links in pages Mosaic has pulled into it's filesystem by making use of the check-links package.
It can identify broken links between the pages themselves and external links that pages link out to.
What this plugin is really checking is "liveness" of a link.
- alive if the URL is reachable (2XX status code)
- dead if the URL is not reachable
- invalid if the URL was parsed as invalid or used an unsupported protocol
Links may be "alive", but the content of the linked page may not be what you want so continue to check links show what you expect.
Links are checked in the background after a source loads, at most four pages at a time, so checking doesn't delay content updates. Broken links, and pages that couldn't be checked, are logged to the console.
This plugin runs with no special priority.
| Property | Description |
|---|---|
| baseUrl | This is used to calculate the full url for links between pages. It should be the url Mosaic is running on |
| proxyEndpoint | If you are behind a corporate proxy, external link checking will not work unless you specify the proxy endpoint using this option |
Add to the plugins collection:
plugins: [
{
modulePath: '@jpmorganchase/mosaic-plugins/BrokenLinksPlugin',
priority: -1,
// Exclude this plugin in builds
runTimeOnly: true,
options: {
baseUrl: process.env.MOSAIC_ACTIVE_MODE_URL || 'http://localhost:8080',
proxyEndpoint: 'http://some-proxy-url'
}
}
// other plugins
];
This plugin needs to be a runtimeOnly plugin because it needs Mosaic to be running in order to
make requests to all of the page links.
When a link is found to be broken, you will see the following output in the console:
@jpmorganchase/mosaic-site:serve: 8080 [Mosaic] Broken links found in /local/docs/publish-site-to-vercel.mdx
@jpmorganchase/mosaic-site:serve: 8080 Link to https://nextjs.org/davie is dead {
@jpmorganchase/mosaic-site:serve: 8080 type: 'link',
@jpmorganchase/mosaic-site:serve: 8080 title: null,
@jpmorganchase/mosaic-site:serve: 8080 url: 'https://nextjs.org/davie',
@jpmorganchase/mosaic-site:serve: 8080 children: [ { type: 'text', value: 'Next.Js', position: [Object] } ],
@jpmorganchase/mosaic-site:serve: 8080 position: {
@jpmorganchase/mosaic-site:serve: 8080 start: { line: 4, column: 20, offset: 36 },
@jpmorganchase/mosaic-site:serve: 8080 end: { line: 4, column: 55, offset: 71 }
@jpmorganchase/mosaic-site:serve: 8080 }
@jpmorganchase/mosaic-site:serve: 8080 }