diff --git a/index.d.ts b/index.d.ts index 80d428e..5456c17 100644 --- a/index.d.ts +++ b/index.d.ts @@ -49,6 +49,9 @@ type EleventyPluginInterlinkOptions = { // slug that you are using. This defaults to a function that returns [UNABLE TO LOCATE EMBED]. unableToLocateEmbedFn?: ErrorRenderFn, + // deadLinkReport is the desired output format of the dead link report, by default its set to 'console' + deadLinkReport?: 'console' | 'json' | 'none', + // resolvingFns is a list of resolving functions. These are invoked by a wikilink containing a `:` character // prefixed by the fn name. The page in this case is the linking page. resolvingFns?: Map Promise>, diff --git a/index.js b/index.js index 8aaf045..6e6bdbd 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ module.exports = function (eleventyConfig, options = {}) { layoutKey: 'embedLayout', layoutTemplateLangKey: 'embedLayoutLanguage', resolvingFns: new Map(), + deadLinkReport: 'console', }, options); // TODO: deprecate usage of unableToLocateEmbedFn in preference of using resolving fn @@ -48,7 +49,9 @@ module.exports = function (eleventyConfig, options = {}) { // anything. // TODO: 1.1.0 have this contain more details such as which file(s) are linking (#23) // TODO: 1.1.0 have this clear the interlinker cache so that next time 11ty builds its starting from fresh data! (#24) - eleventyConfig.on('eleventy.after', () => interlinker.deadLinks.report()); + eleventyConfig.on('eleventy.after', () => { + if (opts.deadLinkReport !== 'none') interlinker.deadLinks.report(opts.deadLinkReport) + }); // Teach Markdown-It how to display MediaWiki Links. eleventyConfig.amendLibrary('md', (md) => { diff --git a/src/dead-links.js b/src/dead-links.js index 34e4ebe..d3c36c5 100644 --- a/src/dead-links.js +++ b/src/dead-links.js @@ -25,17 +25,26 @@ module.exports = class DeadLinks { this.gravestones.set(link, names); } - report() { - for (const [link, files] of this.gravestones.entries()) { - console.warn( - chalk.blue('[@photogabble/wikilinks]'), - chalk.yellow('WARNING'), - `${(link.includes('href') ? 'Link' : 'Wikilink')} (${link}) found pointing to to non-existent page in:` - ); - - for (const file of files) { - console.warn(`\t- ${file}`); + /** + * @param {'console'|'json'} format + */ + report(format) { + if (format === 'console') { + for (const [link, files] of this.gravestones.entries()) { + console.warn( + chalk.blue('[@photogabble/wikilinks]'), + chalk.yellow('WARNING'), + `${(link.includes('href') ? 'Link' : 'Wikilink')} (${link}) found pointing to to non-existent page in:` + ); + + for (const file of files) { + console.warn(`\t- ${file}`); + } } + return; } + + const json = JSON.stringify(this.gravestones); + const n =1; } } diff --git a/tests/fixtures/sample-with-hash-in-title/eleventy.config.js b/tests/fixtures/sample-with-hash-in-title/eleventy.config.js index 9b10b5c..fd8d97b 100644 --- a/tests/fixtures/sample-with-hash-in-title/eleventy.config.js +++ b/tests/fixtures/sample-with-hash-in-title/eleventy.config.js @@ -1,6 +1,9 @@ module.exports = function (eleventyConfig) { eleventyConfig.addPlugin( require('../../../index.js'), + { + deadLinkReport: 'none' + } ); return {