UNPKG

@alauda/doom

Version:

Doctor Doom making docs.

35 lines (34 loc) 1.31 kB
import path from 'node:path'; import { PluginDriver, RouteService, remarkImage, remarkLink, } from '@rspress/core'; import { isProduction } from '@rspress/shared'; import { lintRule } from 'unified-lint-rule'; import { getConfig } from "./utils.js"; export const checkDeadLinks = lintRule('doom-lint:check-dead-links', async (tree, vfile) => { const { config, configFilePath } = await getConfig(); const relativePath = path.relative(config.root, vfile.path); // Ignore files outside the root directory if (relativePath.startsWith('..')) { return; } let routeService = RouteService.getInstance(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!routeService) { const pluginDriver = await PluginDriver.create(config, configFilePath, isProduction()); routeService = await RouteService.create({ config, scanDir: config.root, externalPages: await pluginDriver.addPages(), }); } remarkLink({ cleanUrls: false, routeService, remarkLinkOptions: config.markdown?.link, lint: true, })(tree, vfile); remarkImage({ docDirectory: config.root, remarkImageOptions: config.markdown?.image, lint: true, })(tree, vfile); });