links-check
This plugin checks for dead links in your markdown files.
This plugin has been integrated into the default theme.
Usage
npm i -D @vuepress/plugin-links-check@nextimport { linksCheckPlugin } from '@vuepress/plugin-links-check'
export default {
plugins: [
linksCheckPlugin({
// options
}),
],
}Guide
Link Checking
The plugin checks every markdown link, and warns for the links whose target file does not exist.
Links are checked in both dev server and build. Set build: 'error' to fail the build when dead links are found.
Use exclude to skip the links that are intentionally broken, by string, regular expression or function.
Anchor Checking
Anchors of links are checked as well. A link is broken when its anchor does not exist in the target page, no matter whether the target page is the current page or another page.
The following anchors are recognized:
- Heading ids, including the custom ids given by
{#custom-id}. - Ids in raw html, e.g.
<div id="foo">. - Ids published by other markdown plugins, such as the field ids generated by
@vuepress/plugin-markdown-field.
Set anchors: 'same-page' to only check the anchors pointing to the current page, or false to skip anchor checking.
Anchors of a link are not checked when its target page is not rendered by markdown, since the anchors of that page are unknown.
With anchor checking, a link is compared with exclude both as it is written (including the anchor) and as its path without the anchor.
Options
booleantrueWhether to check dead links in markdown in dev server.
boolean | 'error'trueWhether to check dead links in markdown during build. If set to 'error', the build will fail when dead links are found.
boolean | 'same-page'trueWhether to check anchors of links. Set to 'same-page' to only check the anchors pointing to the current page, or false to skip anchor checking.
See also: Anchor Checking.
(string | RegExp)[] | ((link: string, isDev: boolean) => boolean)Links to exclude from checking. You can use a list of strings or regular expressions, or a function that returns a boolean.
import { linksCheckPlugin } from '@vuepress/plugin-links-check'
export default {
plugins: [
linksCheckPlugin({
exclude: [
// exclude links by string
'/exclude-link',
// exclude links by regex
/\/exclude-link-regex/,
],
// or exclude links by function
exclude: (link, isDev) => {
if (isDev) {
return link.startsWith('/exclude-link-dev')
}
return link.startsWith('/exclude-link-build')
},
}),
],
}