Skip to content

Commit

Permalink
feat(v2): add a new site config prop called onBrokenMarkdownLinks
Browse files Browse the repository at this point in the history
works like onBrokenLinks, but only for markdown links
  • Loading branch information
AmyrAhmady committed Oct 31, 2020
1 parent fca8530 commit 15f2b8f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export function createConfigFile({
favicon: siteConfig.favicon ?? '',
customFields: customConfigFields,
onBrokenLinks: 'log',
onBrokenMarkdownLinks: 'log',
presets: [
[
'@docusaurus/preset-classic',
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-migrate/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface VersionTwoConfig {
noIndex?: boolean;
githubHost?: string;
onBrokenLinks: string;
onBrokenMarkdownLinks: string;
plugins: Array<[string, {[key: string]: any}]>;
themes?: [];
presets: [[string, ClassicPresetEntries]];
Expand Down
7 changes: 5 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,16 @@ export default function pluginContentDocs(
sourceToPermalink,
versionsMetadata,
onBrokenMarkdownLink: (brokenMarkdownLink) => {
if (siteConfig.onBrokenLinks === 'ignore') {
if (
siteConfig.onBrokenMarkdownLinks === 'ignore' ||
!siteConfig.onBrokenMarkdownLinks
) {
return;
}

reportMessage(
`Docs markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath} for version ${brokenMarkdownLink.version.versionName}`,
siteConfig.onBrokenLinks,
siteConfig.onBrokenMarkdownLinks,
);
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface DocusaurusConfig {
title: string;
url: string;
onBrokenLinks: ReportingSeverity;
onBrokenMarkdownLinks: ReportingSeverity;
onDuplicateRoutes: ReportingSeverity;
noIndex: boolean;
organizationName?: string;
Expand Down
5 changes: 5 additions & 0 deletions packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
export const DEFAULT_CONFIG: Pick<
DocusaurusConfig,
| 'onBrokenLinks'
| 'onBrokenMarkdownLinks'
| 'onDuplicateRoutes'
| 'plugins'
| 'themes'
Expand All @@ -27,6 +28,7 @@ export const DEFAULT_CONFIG: Pick<
| 'noIndex'
> = {
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
onDuplicateRoutes: 'warn',
plugins: [],
themes: [],
Expand Down Expand Up @@ -64,6 +66,9 @@ const ConfigSchema = Joi.object({
onBrokenLinks: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.default(DEFAULT_CONFIG.onBrokenLinks),
onBrokenMarkdownLinks: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.default(DEFAULT_CONFIG.onBrokenLinks),
onDuplicateRoutes: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.default(DEFAULT_CONFIG.onDuplicateRoutes),
Expand Down
1 change: 1 addition & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
baseUrl,
url: 'https://v2.docusaurus.io',
onBrokenLinks: isVersioningDisabled ? 'warn' : 'throw',
onBrokenMarkdownLinks: 'warn',
favicon: 'img/docusaurus.ico',
customFields: {
description:
Expand Down

0 comments on commit 15f2b8f

Please sign in to comment.