forked from PalisadoesFoundation/talawa-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-repo-url.js
28 lines (23 loc) · 816 Bytes
/
fix-repo-url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import fs from 'fs';
import path from 'path';
const docsDir = path.resolve('./docs/docs/auto-docs');
const mainRepoUrl =
'https://github.com/PalisadoesFoundation/talawa-admin/blob/main/';
function replaceRepoUrl(dir) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
replaceRepoUrl(filePath);
} else if (file.endsWith('.md')) {
let content = fs.readFileSync(filePath, 'utf8');
// Replace any repository URL before the "src" directory with the main repository URL
content = content.replace(
/https:\/\/github\.com\/[^/]+\/[^/]+\/blob\/[^/]+\//g,
mainRepoUrl,
);
fs.writeFileSync(filePath, content, 'utf8');
}
});
}
replaceRepoUrl(docsDir);