1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-30 12:40:03 +02:00

Add command to collect links from roadmaps

This commit is contained in:
Kamran Ahmed
2023-01-09 15:35:45 +04:00
parent ed8bf11150
commit 18e4804a51
2 changed files with 46 additions and 1 deletions

44
bin/roadmap-links.cjs Normal file
View File

@@ -0,0 +1,44 @@
const fs = require('fs');
const path = require('path');
const roadmapId = process.argv[2];
if (!roadmapId) {
console.error('Error: roadmapId is required');
}
const fullPath = path.join(__dirname, `../src/roadmaps/${roadmapId}`);
if (!fs.existsSync(fullPath)) {
console.error(`Error: path not found: ${fullPath}!`);
process.exit(1);
}
function readFiles(folderPath) {
const stats = fs.lstatSync(folderPath);
if (stats.isFile()) {
return [folderPath];
}
const folderContent = fs.readdirSync(folderPath);
let files = [];
for (const file of folderContent) {
const filePath = path.join(folderPath, file);
files = [...files, ...readFiles(filePath)];
}
return files;
}
const files = readFiles(fullPath);
let allLinks = [];
files.forEach((file) => {
const fileContent = fs.readFileSync(file, 'utf-8');
const matches = [...fileContent.matchAll(/\[[^\]]+]\((https?:\/\/[^)]+)\)/g)];
allLinks = [...allLinks, ...matches.map((match) => match[1])];
});
allLinks.map((link) => console.log(link));

View File

@@ -12,7 +12,8 @@
"deploy": "NODE_DEBUG=gh-pages gh-pages -d dist -t",
"sync-content": "sh ./bin/sync-content.sh",
"compress:jsons": "node bin/compress-jsons.cjs",
"upgrade": "ncu -u"
"upgrade": "ncu -u",
"roadmap-links": "node bin/roadmap-links.cjs"
},
"dependencies": {
"@astrojs/sitemap": "^1.0.0",