Skip to content

Commit 7340aca

Browse files
authored
Merge pull request #2453 from webpack/rebuild-fix-readme-badges
Fix regressions from #2451
2 parents b00d92a + b92a6f5 commit 7340aca

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"lint:markdown": "markdownlint --config ./.markdownlint.json *.md ./src/content/**/*.md --ignore './src/content/**/_*.md'",
4343
"lint:social": "alex . -q",
4444
"lint:prose": "cp .proselintrc ~/ && proselint src/content",
45-
"lint:links": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ -i --todo https://img.shields.io | tee internal-links.tap | tap-spot",
45+
"lint:links": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ -i --todo https://img.shields.io --todo 'content-type-mismatch https://travis-ci.org' | tee internal-links.tap | tap-spot",
4646
"linkcheck": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ --skip support__ --skip sidecar.gitter.im --skip vimdoc.sourceforge.net --skip img.shields.io --skip npmjs.com/package/ --skip opencollective.com/webpack --todo external-redirect | tee external-links.tap | tap-spot",
4747
"sitemap": "cd dist && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml",
4848
"serve": "npm run build && sirv start ./dist --port 4000",

src/utilities/process-readme.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const url = require('url');
22

3+
const beginsWithDocsDomainRegex = /^https?:\/\/webpack\.js\.org/;
4+
35
module.exports = function processREADME(body, options = {}) {
46
return body
57
.replace(/[^]*?<div align="center">([^]*?)<\/div>/, (match, content) => {
@@ -14,11 +16,27 @@ module.exports = function processREADME(body, options = {}) {
1416
// EXAMPLE: [Contributing](./.github/CONTRIBUTING.md)
1517
// EXAMPLE: [Contributing](CONTRIBUTING.md)
1618
.replace(/\[([^\]]*)\]\(([^)]+)\)/g, (markdownLink, content, href) => {
19+
const oldHref = href;
20+
1721
if (href.includes('//npmjs.com')) {
1822
href = href.replace('//www.npmjs.com');
1923
}
2024

21-
return `[${content}](${url.resolve(options.source, href)})`;
25+
// Only resolve non-absolute urls from their source if they are not a document fragment link
26+
if (!href.startsWith('#')) {
27+
href = url.resolve(options.source, href);
28+
}
29+
30+
// Modify absolute documenation links to be root relative
31+
if (beginsWithDocsDomainRegex.test(href)) {
32+
href = href.replace(beginsWithDocsDomainRegex, '');
33+
}
34+
35+
if (oldHref !== href) {
36+
console.log('REWRITE URL:', oldHref, '-->', href);
37+
}
38+
39+
return `[${content}](${href})`;
2240
})
2341
// Modify links to keep them within the site
2442
.replace(/https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-loader\/?)([)"])/g, '/loaders/$2/$3')

0 commit comments

Comments
 (0)