From fbdc7e754a13c666e4d1316fda8f3a43a45f274e Mon Sep 17 00:00:00 2001 From: Brian 'bdougie' Douglas Date: Thu, 3 Jul 2025 18:23:55 -0700 Subject: [PATCH] run prettier --- docs/docusaurus.config.js | 2 +- docs/plugins/custom-llms-txt.js | 127 +++++++++++++++++--------------- 2 files changed, 69 insertions(+), 60 deletions(-) diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 7e24136d4..2ce94b2c6 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -204,7 +204,7 @@ const config = { }, ], // Custom plugin for better structured llms.txt - require.resolve('./plugins/custom-llms-txt.js'), + require.resolve("./plugins/custom-llms-txt.js"), // Keeping the original plugin commented out for now // [ // "docusaurus-plugin-llms-txt", diff --git a/docs/plugins/custom-llms-txt.js b/docs/plugins/custom-llms-txt.js index 44bfbd7d5..30762c9c1 100644 --- a/docs/plugins/custom-llms-txt.js +++ b/docs/plugins/custom-llms-txt.js @@ -1,121 +1,130 @@ -const fs = require('fs'); -const path = require('path'); +const fs = require("fs"); +const path = require("path"); function getAllHtmlFiles(dir, fileList = []) { const files = fs.readdirSync(dir); - - files.forEach(file => { + + files.forEach((file) => { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); - + if (stat.isDirectory()) { getAllHtmlFiles(filePath, fileList); - } else if (file === 'index.html') { + } else if (file === "index.html") { fileList.push(filePath); } }); - + return fileList; } module.exports = function customLLMsTxtPlugin(context, options) { return { - name: 'custom-llms-txt', + name: "custom-llms-txt", async postBuild({ siteConfig, outDir }) { // Group docs by their sidebar category const sections = { - 'Getting Started': [], - 'Features': [], - 'Guides': [], - 'Customization': [], - 'Advanced': [], - 'Hub': [] + "Getting Started": [], + Features: [], + Guides: [], + Customization: [], + Advanced: [], + Hub: [], }; - + // Get all HTML files const htmlFiles = getAllHtmlFiles(outDir); - + for (const htmlPath of htmlFiles) { try { - const htmlContent = fs.readFileSync(htmlPath, 'utf8'); - + const htmlContent = fs.readFileSync(htmlPath, "utf8"); + // Extract title from HTML (handle both formats) const titleMatch = htmlContent.match(/]*>([^<]+)<\/title>/); - const title = titleMatch ? titleMatch[1].replace(' | Continue', '').trim() : 'Untitled'; - + const title = titleMatch + ? titleMatch[1].replace(" | Continue", "").trim() + : "Untitled"; + // Skip if title is just "Continue" (likely homepage) - if (title === 'Continue') continue; - + if (title === "Continue") continue; + // Extract description from meta tag - const descMatch = htmlContent.match(/ { if (docs.length > 0) { content += `## ${sectionName}\n\n`; - + // Sort docs within each section docs.sort((a, b) => { // Sort by path depth first (shorter paths first) const depthA = (a.path.match(/\//g) || []).length; const depthB = (b.path.match(/\//g) || []).length; if (depthA !== depthB) return depthA - depthB; - + // Then alphabetically return a.path.localeCompare(b.path); }); - - docs.forEach(doc => { + + docs.forEach((doc) => { content += `- [${doc.title}](${doc.url})`; if (doc.description) { content += `: ${doc.description}`; } - content += '\n'; + content += "\n"; }); - content += '\n'; + content += "\n"; } }); - + // Write to file - const outputPath = path.join(outDir, 'llms.txt'); - fs.writeFileSync(outputPath, content, 'utf8'); - - console.log(`Generated structured llms.txt with ${Object.values(sections).flat().length} pages`); - } + const outputPath = path.join(outDir, "llms.txt"); + fs.writeFileSync(outputPath, content, "utf8"); + + console.log( + `Generated structured llms.txt with ${Object.values(sections).flat().length} pages`, + ); + }, }; -}; \ No newline at end of file +};