mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
feat(v2): onBrokenMarkdownLinks config (#3658)
* refactor(v2): move `reportMessage` from `core/src/server/utils` to `utils` package * feat(v2): handle broken markdown links by using onBrokenLinks prop from siteconfig * feat(v2): add a new site config prop called `onBrokenMarkdownLinks` works like onBrokenLinks, but only for markdown links * feat(v2): add `onBrokenMarkdownLinks` to API docs * some changes regarding test issues after adding `onBrokenMarkdownLink` * Update website/versioned_docs/version-2.0.0-alpha.66/api/docusaurus.config.js.md Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
parent
52e7511869
commit
8f2d898f22
18 changed files with 71 additions and 38 deletions
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
import {createHash} from 'crypto';
|
||||
|
@ -13,6 +14,7 @@ import kebabCase from 'lodash.kebabcase';
|
|||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import fs from 'fs-extra';
|
||||
import {URL} from 'url';
|
||||
import {ReportingSeverity} from '@docusaurus/types';
|
||||
|
||||
// @ts-expect-error: no typedefs :s
|
||||
import resolvePathnameUnsafe from 'resolve-pathname';
|
||||
|
@ -436,3 +438,28 @@ export function getElementsAround<T extends unknown>(
|
|||
const next = aroundIndex === max ? undefined : array[aroundIndex + 1];
|
||||
return {previous, next};
|
||||
}
|
||||
|
||||
export function reportMessage(
|
||||
message: string,
|
||||
reportingSeverity: ReportingSeverity,
|
||||
): void {
|
||||
switch (reportingSeverity) {
|
||||
case 'ignore':
|
||||
break;
|
||||
case 'log':
|
||||
console.log(chalk.bold.blue('info ') + chalk.blue(message));
|
||||
break;
|
||||
case 'warn':
|
||||
console.warn(chalk.bold.yellow('warn ') + chalk.yellow(message));
|
||||
break;
|
||||
case 'error':
|
||||
console.error(chalk.bold.red('error ') + chalk.red(message));
|
||||
break;
|
||||
case 'throw':
|
||||
throw new Error(message);
|
||||
default:
|
||||
throw new Error(
|
||||
`unexpected reportingSeverity value: ${reportingSeverity}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue