Skip to content

Commit

Permalink
Merge pull request #26 from photogabble/patch/v1.1.0/#23
Browse files Browse the repository at this point in the history
FEATURE: Add detailed bad link report
  • Loading branch information
carbontwelve authored May 1, 2024
2 parents 7d20e2c + ae44b1a commit 6499b07
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 30 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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.deadLinksReport());
eleventyConfig.on('eleventy.after', () => interlinker.deadLinks.report());

// Teach Markdown-It how to display MediaWiki Links.
eleventyConfig.amendLibrary('md', (md) => {
Expand Down
203 changes: 203 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@11ty/eleventy": "^2.0.0",
"ava": "^5.2.0",
"c8": "^7.12.0",
"sinon": "^17.0.1",
"slugify": "^1.6.6"
},
"directories": {
Expand Down
41 changes: 41 additions & 0 deletions src/dead-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const chalk = require("chalk");
module.exports = class DeadLinks {

constructor() {
this.gravestones = new Map;
this.fileSrc = 'unknown';
}

setFileSrc(fileSrc) {
this.fileSrc = fileSrc;
}

/**
* @param {string} link
*/
add(link) {
if (!this.fileSrc) this.fileSrc = 'unknown';

const names = this.gravestones.has(link)
? this.gravestones.get(this.fileSrc)
: [];

names.push(this.fileSrc)

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}`);
}
}
}
}
Loading

0 comments on commit 6499b07

Please sign in to comment.