|
| 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