Skip to content

Commit c417855

Browse files
committed
refactor: migrate URL fixing script to ES modules and update package.json reference
1 parent 395ffb4 commit c417855

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"format:diff": "prettier --list-different .",
2020
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,md,mdx}\"",
2121
"lint": "npx eslint .",
22-
"fix-llms-urls": "node scripts/fix-llms-urls.js",
22+
"fix-llms-urls": "node scripts/fix-llms-urls.mjs",
2323
"build:llms-fixed": "npm run build && npm run fix-llms-urls"
2424
},
2525
"dependencies": {

scripts/fix-llms-urls.js

100755100644
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* generates routes (e.g., "0-overview" becomes "overview")
88
*/
99

10-
const fs = require("fs");
11-
const path = require("path");
10+
import fs from "fs";
11+
import path from "path";
1212

1313
const config = {
1414
buildDir: "build",
@@ -58,8 +58,8 @@ function main() {
5858
console.log("✅ URL fixing completed!");
5959
}
6060

61-
if (require.main === module) {
61+
if (import.meta.url === `file://${process.argv[1]}`) {
6262
main();
6363
}
6464

65-
module.exports = { fixUrlsInFile, main };
65+
export { fixUrlsInFile, main };

scripts/fix-llms-urls.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script to fix URLs in generated LLMs files to match Docusaurus routing
5+
*
6+
* This script removes prepended numbers from URLs to match how Docusaurus
7+
* generates routes (e.g., "0-overview" becomes "overview")
8+
*/
9+
10+
import fs from "fs";
11+
import path from "path";
12+
13+
const config = {
14+
buildDir: "build",
15+
filesToFix: ["llms.txt", "llms-full.txt"],
16+
baseUrl: "https://dev.flare.network/docs/",
17+
};
18+
19+
function fixUrlsInFile(filePath) {
20+
try {
21+
console.log(`Fixing URLs in: ${filePath}`);
22+
23+
const content = fs.readFileSync(filePath, "utf8");
24+
25+
// Fix URLs by removing prepended numbers
26+
// Pattern: https://dev.flare.network/docs/network/0-overview -> https://dev.flare.network/docs/network/overview
27+
const fixedContent = content.replace(
28+
/(https:\/\/dev\.flare\.network\/docs\/[^)]+\/)\d+-([^)]+)/g,
29+
"$1$2",
30+
);
31+
32+
fs.writeFileSync(filePath, fixedContent);
33+
34+
console.log(`✅ Fixed URLs in: ${filePath}`);
35+
} catch (error) {
36+
console.error(`❌ Error fixing URLs in ${filePath}:`, error.message);
37+
}
38+
}
39+
40+
function main() {
41+
console.log("🔧 Fixing URLs in LLMs files...");
42+
43+
if (!fs.existsSync(config.buildDir)) {
44+
console.error(`❌ Build directory not found: ${config.buildDir}`);
45+
return;
46+
}
47+
48+
config.filesToFix.forEach((fileName) => {
49+
const filePath = path.join(config.buildDir, fileName);
50+
51+
if (fs.existsSync(filePath)) {
52+
fixUrlsInFile(filePath);
53+
} else {
54+
console.warn(`⚠️ File not found: ${filePath}`);
55+
}
56+
});
57+
58+
console.log("✅ URL fixing completed!");
59+
}
60+
61+
if (import.meta.url === `file://${process.argv[1]}`) {
62+
main();
63+
}
64+
65+
export { fixUrlsInFile, main };

0 commit comments

Comments
 (0)