mirror of https://github.com/FOME-Tech/wiki.git
Refactor linkValidator
This commit is contained in:
parent
7672457443
commit
8ffcbfa230
|
@ -1,8 +1,10 @@
|
|||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
|
||||
const red = (text) => `\x1b[31m${text}\x1b[0m`;
|
||||
|
||||
/**
|
||||
* Load all md and mdx files from /docs and check whether links are not staring with "wiki.fome.tech"
|
||||
* Check whether links are not staring with "wiki.fome.tech"
|
||||
* @param {Array<string>} files - List of file names to check
|
||||
*/
|
||||
const validateAbsoluteUrls = (files) => {
|
||||
|
@ -12,6 +14,8 @@ const validateAbsoluteUrls = (files) => {
|
|||
/** @type {Array<{ fileName: string, lineContent: string, lineNo: number }>} */
|
||||
const errors = [];
|
||||
|
||||
console.log('Validating absolute URLs...');
|
||||
|
||||
files.forEach((fileName) => {
|
||||
const lines = fs.readFileSync(fileName, 'utf8').split('\n');
|
||||
|
||||
|
@ -28,7 +32,7 @@ const validateAbsoluteUrls = (files) => {
|
|||
|
||||
if (errors.length > 0) {
|
||||
console.log('❌ Failed\n');
|
||||
console.log(`Absolute URLs to "${wikiUrl}" found in the following files:\n`);
|
||||
console.log(red(`Absolute URLs to "${wikiUrl}" found in the following files:\n`));
|
||||
errors.forEach((error) => {
|
||||
console.log(
|
||||
`[${error.fileName}:${error.lineNo}] ${error.lineContent.trim()}`
|
||||
|
@ -37,12 +41,19 @@ const validateAbsoluteUrls = (files) => {
|
|||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all md and mdx files from / docs and process them
|
||||
*/
|
||||
const main = () => {
|
||||
const files = glob.sync('docs/**/*.md?(x)');
|
||||
|
||||
// process
|
||||
validateAbsoluteUrls(files);
|
||||
// validateRelativeUrls(files);
|
||||
|
||||
console.log('✅ Ok');
|
||||
}
|
||||
|
||||
const files = glob.sync('docs/**/*.md?(x)');
|
||||
|
||||
console.log('Validating links...');
|
||||
|
||||
validateAbsoluteUrls(files);
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue