docs/verify-links: update to disallow path-absolute doc links
This commit is contained in:
+22
-7
@@ -42,14 +42,25 @@ async function verifyUrl(basePath, url) {
|
||||
}
|
||||
|
||||
// Only verify existence of local files for now, so skip anything with a schema
|
||||
if (!url.match(/[a-z]+:/)) {
|
||||
const path = url.startsWith('/')
|
||||
? resolvePath(projectRoot, `.${url}`)
|
||||
: resolvePath(dirname(resolvePath(projectRoot, basePath)), url);
|
||||
const exists = await fs.pathExists(path);
|
||||
if (!exists) {
|
||||
return { url, basePath, problem: 'missing' };
|
||||
if (url.match(/[a-z]+:/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let path = '';
|
||||
|
||||
if (url.startsWith('/')) {
|
||||
if (url.startsWith('/docs/') && basePath.match(/^(?:docs|microsite)\//)) {
|
||||
return { url, basePath, problem: 'not-relative' };
|
||||
}
|
||||
|
||||
path = resolvePath(projectRoot, `.${url}`);
|
||||
} else {
|
||||
path = resolvePath(dirname(resolvePath(projectRoot, basePath)), url);
|
||||
}
|
||||
|
||||
const exists = await fs.pathExists(path);
|
||||
if (!exists) {
|
||||
return { url, basePath, problem: 'missing' };
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -93,6 +104,10 @@ async function main() {
|
||||
for (const { url, basePath, problem } of badUrls) {
|
||||
if (problem === 'missing') {
|
||||
console.error(`Unable to reach ${url}, linked from ${basePath}`);
|
||||
} else if (problem === 'not-relative') {
|
||||
console.error('Links to /docs/ must be relative');
|
||||
console.error(` From: ${basePath}`);
|
||||
console.error(` To: ${url}`);
|
||||
} else if (problem === 'absolute') {
|
||||
console.error(`Link to docs/ should be replaced by a relative URL`);
|
||||
console.error(` From: ${basePath}`);
|
||||
|
||||
Reference in New Issue
Block a user