Skip to content

Commit

Permalink
feat(v2): handle broken markdown links by using onBrokenLinks prop fr…
Browse files Browse the repository at this point in the history
…om siteconfig
  • Loading branch information
AmyrAhmady committed Oct 30, 2020
1 parent 99294bd commit d898923
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
STATIC_DIR_NAME,
DEFAULT_PLUGIN_ID,
} from '@docusaurus/core/lib/constants';
import {normalizeUrl, docuHash, aliasedSitePath} from '@docusaurus/utils';
import {normalizeUrl, docuHash, aliasedSitePath, reportMessage} from '@docusaurus/utils';
import {LoadContext, Plugin, RouteConfig} from '@docusaurus/types';

import {loadSidebars, createSidebarsUtils} from './sidebars';
Expand Down Expand Up @@ -39,13 +39,12 @@ import {OptionsSchema} from './options';
import {flatten, keyBy, compact} from 'lodash';
import {toGlobalDataVersion} from './globalData';
import {toVersionMetadataProp} from './props';
import chalk from 'chalk';

export default function pluginContentDocs(
context: LoadContext,
options: PluginOptions,
): Plugin<LoadedContent, typeof OptionsSchema> {
const {siteDir, generatedFilesDir, baseUrl} = context;
const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;

const versionsMetadata = readVersionsMetadata({context, options});

Expand Down Expand Up @@ -311,11 +310,13 @@ export default function pluginContentDocs(
sourceToPermalink,
versionsMetadata,
onBrokenMarkdownLink: (brokenMarkdownLink) => {
// TODO make this warning configurable?
console.warn(
chalk.yellow(
if(siteConfig.onBrokenLinks === 'ignore') {
return;
}

reportMessage(
`Docs markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath} for version ${brokenMarkdownLink.version.versionName}`,
),
siteConfig.onBrokenLinks
);
},
};
Expand Down

0 comments on commit d898923

Please sign in to comment.