Skip to content

Commit

Permalink
feat(nx-dev): check for missing images
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacplmann committed May 8, 2024
1 parent dfb994d commit e9bf37a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/nx-cloud/set-up/azure-devops.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For example, a URL of `https://dev.azure.com/nrwl/_git/large-monorepo` has the r

To use a Personal Access Token for authentication, one must be generated with proper permissions. The minimum required permissions are shown in the screenshot below.

![Work Items - Read, Code - Read, Build - Read & execute, Release - Read, write, & execute](/nx-cloud/set-up/minimal-ado-access-token.webp 'Minimum Azure DevOps Personal Access Token Permissions')
![Work Items - Read, Code - Read, Build - Read & execute, Release - Read, write, & execute](/nx-cloud/set-up/minimal-ado-access-token.webp)

Once this token is created paste the value and then click "Connect".

Expand Down
24 changes: 22 additions & 2 deletions scripts/documentation/internal-link-checker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { workspaceRoot } from '@nx/devkit';
import { XMLParser } from 'fast-xml-parser';
import { existsSync, readJSONSync } from 'fs-extra';
import * as glob from 'glob';
import { readFileSync } from 'node:fs';
import { readFileSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import * as parseLinks from 'parse-markdown-links';

Expand Down Expand Up @@ -52,6 +51,18 @@ function extractAllLinks(basePath: string): Record<string, string[]> {
return acc;
}, {});
}
function extractImageLinks(basePath: string): Record<string, string[]> {
return glob.sync(`${basePath}/**/*.md`).reduce((acc, path) => {
const fileContents = readFileContents(path);
const imageLinks = Array.from(
fileContents.matchAll(/!\[.*?\]\((.*?)\)/g)
).map((matches) => decodeURI(matches[1]));
if (imageLinks.length) {
acc[path.replace(basePath, '')] = imageLinks;
}
return acc;
}, {});
}
function readSiteMapIndex(directoryPath: string, filename: string): string[] {
const parser = new XMLParser();
const sitemapIndex: {
Expand Down Expand Up @@ -98,6 +109,15 @@ for (let file in documentLinks) {
}
}

const imageLinks = extractImageLinks(join(workspaceRoot, 'docs'));
for (let file in imageLinks) {
for (let link of imageLinks[file]) {
if (!existsSync(join(workspaceRoot, 'docs', link))) {
errors.push({ file, link });
}
}
}

console.log(`i/ Internal Link Check`);
if (errors.length) {
console.log(`ERROR\n${errors.length} links are pointing to nowhere:`);
Expand Down

0 comments on commit e9bf37a

Please sign in to comment.