From 9037281eef07289aaf04da6caf97986463aa0ee3 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 19 Apr 2022 17:32:54 +0200 Subject: [PATCH] scripts/verify-links: tweak to allow GitHub links to changelogs from docs Signed-off-by: Patrik Oldsberg --- scripts/verify-links.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/verify-links.js b/scripts/verify-links.js index 25bdaa2ac3..05ad387c37 100755 --- a/scripts/verify-links.js +++ b/scripts/verify-links.js @@ -43,6 +43,13 @@ async function listFiles(dir) { const projectRoot = resolvePath(__dirname, '..'); async function verifyUrl(basePath, absUrl, docPages) { + const url = absUrl + .replace(/#.*$/, '') + .replace( + /https:\/\/github.com\/backstage\/backstage\/(tree|blob)\/master/, + '', + ); + // Avoid having absolute URL links within docs/, so that links work on the site if ( absUrl.match( @@ -50,15 +57,17 @@ async function verifyUrl(basePath, absUrl, docPages) { ) && basePath.match(/^(?:docs|microsite)\//) ) { + // Exception for linking to the changelogs, since we encourage those to be browsed in GitHub + if (absUrl.match(/docs\/releases\/.+-changelog\.md$/)) { + if (docPages.has(url.slice(0, -'.md'.length))) { + return undefined; + } + return { url: absUrl, basePath, problem: 'missing' }; + } + return { url: absUrl, basePath, problem: 'github' }; } - const url = absUrl - .replace(/#.*$/, '') - .replace( - /https:\/\/github.com\/backstage\/backstage\/(tree|blob)\/master/, - '', - ); if (!url) { return undefined; }