Skip to content

Fix regressions from #2451 #2453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"lint:markdown": "markdownlint --config ./.markdownlint.json *.md ./src/content/**/*.md --ignore './src/content/**/_*.md'",
"lint:social": "alex . -q",
"lint:prose": "cp .proselintrc ~/ && proselint src/content",
"lint:links": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ -i --todo https://img.shields.io | tee internal-links.tap | tap-spot",
"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",
"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",
"sitemap": "cd dist && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml",
"serve": "npm run build && sirv start ./dist --port 4000",
Expand Down
20 changes: 19 additions & 1 deletion src/utilities/process-readme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const url = require('url');

const beginsWithDocsDomainRegex = /^https?:\/\/webpack\.js\.org/;

module.exports = function processREADME(body, options = {}) {
return body
.replace(/[^]*?<div align="center">([^]*?)<\/div>/, (match, content) => {
Expand All @@ -14,11 +16,27 @@ module.exports = function processREADME(body, options = {}) {
// EXAMPLE: [Contributing](./.github/CONTRIBUTING.md)
// EXAMPLE: [Contributing](CONTRIBUTING.md)
.replace(/\[([^\]]*)\]\(([^)]+)\)/g, (markdownLink, content, href) => {
const oldHref = href;

if (href.includes('//npmjs.com')) {
href = href.replace('//www.npmjs.com');
}

return `[${content}](${url.resolve(options.source, href)})`;
// Only resolve non-absolute urls from their source if they are not a document fragment link
if (!href.startsWith('#')) {
href = url.resolve(options.source, href);
}

// Modify absolute documenation links to be root relative
if (beginsWithDocsDomainRegex.test(href)) {
href = href.replace(beginsWithDocsDomainRegex, '');
}

if (oldHref !== href) {
console.log('REWRITE URL:', oldHref, '-->', href);
}

return `[${content}](${href})`;
})
// Modify links to keep them within the site
.replace(/https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-loader\/?)([)"])/g, '/loaders/$2/$3')
Expand Down