docusaurus-plugin-llms-txt
Version:
A Docusaurus plugin for creating llms.txt and llms-full.txt files
47 lines (46 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateLLMsTxt = generateLLMsTxt;
exports.generateFullLLMsTxt = generateFullLLMsTxt;
function createTitleSection(options) {
const description = options.description ? `\n\n> ${options.description}` : '';
return `# ${options.title}${description}\n\n`;
}
function groupRoutesBySection(routes) {
return routes.reduce((acc, route) => {
const section = route.section_name;
if (!acc[section]) {
acc[section] = [];
}
acc[section].push(route);
return acc;
}, {});
}
function createSectionContent(routes) {
// Group routes by section_name
const routesBySection = groupRoutesBySection(routes);
// Create markdown for each section
return Object.entries(routesBySection).map(([sectionName, sectionRoutes]) => {
const routesList = sectionRoutes
.map(route => {
const link = `[${route.title}](${route.url})`;
return route.description ? `- ${link}: ${route.description}` : `- ${link}`;
})
.join('\n');
return `## ${sectionName}\n\n${routesList}`;
}).join('\n\n');
}
function createFullSectionContent(routes) {
return routes.map((route) => route.content).join('\n\n');
}
function generateLLMsTxt(routes, options) {
const titleSection = createTitleSection(options);
const content = createSectionContent(routes);
return titleSection + content;
}
function generateFullLLMsTxt(routes, options) {
let llmsTxt = createTitleSection(options);
// Group routes by section_name
const mergedContent = createFullSectionContent(routes);
return llmsTxt + mergedContent;
}