Skip to content

Commit

Permalink
slightly cleaner llms-full.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrell committed Feb 19, 2025
1 parent 22208d5 commit 2f25d1c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,22 @@ const config: Config = {
await getMdxFiles(fullPath);
} else if (entry.name.endsWith(".mdx")) {
const content = await fs.promises.readFile(fullPath, "utf8");
allMdx.push(content);

// extract title from frontmatter if it exists
const titleMatch = content.match(
/^---\n(?:.*\n)*?title:\s*["']?([^"'\n]+)["']?\n(?:.*\n)*?---\n/
);
const title = titleMatch ? titleMatch[1] : "";

// strip frontmatter
const contentWithoutFrontmatter = content.replace(/^---\n[\s\S]*?\n---\n/, "");

// combine title and content
const contentWithTitle = title
? `# ${title}\n${contentWithoutFrontmatter}`
: contentWithoutFrontmatter;

allMdx.push(contentWithTitle);
}
}
};
Expand All @@ -123,7 +138,7 @@ const config: Config = {

// Write concatenated MDX content
const concatenatedPath = path.join(outDir, "llms-full.txt");
await fs.promises.writeFile(concatenatedPath, allMdx.join("\n\n---\n\n"));
await fs.promises.writeFile(concatenatedPath, allMdx.join("\n---\n\n"));

// we need to dig down several layers:
// find PluginRouteConfig marked by plugin.name === "docusaurus-plugin-content-docs"
Expand Down

0 comments on commit 2f25d1c

Please sign in to comment.