Skip to content

feat: add LLM-ready markdown export (append .md to any URL)#2403

Open
jcstein wants to merge 1 commit intomainfrom
jcs/mdlinks
Open

feat: add LLM-ready markdown export (append .md to any URL)#2403
jcstein wants to merge 1 commit intomainfrom
jcs/mdlinks

Conversation

@jcstein
Copy link
Member

@jcstein jcstein commented Feb 5, 2026

Summary

  • Implements automatic generation of clean markdown files from MDX sources
  • Users can now append .md to any documentation URL to get LLM-friendly markdown
  • Similar to Solana's implementation, making docs easily consumable by AI tools

What's Changed

  • Enhanced generate-llms.js script: Now generates individual .md files for each .mdx page
  • Build process integration: Markdown generation runs automatically during yarn build
  • Smart content cleaning: Removes JSX components, imports, and MDX-specific syntax while preserving actual documentation content
  • Flexible output: Writes to out/ during build, public/ during development

How It Works

Simply append .md to any documentation URL:

  • https://docs.celestia.org/learn/TIA/overviewhttps://docs.celestia.org/learn/TIA/overview.md
  • https://docs.celestia.org/build/private-blockspace/quickstarthttps://docs.celestia.org/build/private-blockspace/quickstart.md

Benefits

  • 🤖 LLM-friendly: Clean markdown perfect for AI consumption
  • 🔗 Simple API: Just add .md to any existing URL
  • 🚀 Zero runtime overhead: Files are pre-generated during build
  • 📦 No new dependencies: Uses only existing Node.js capabilities

Test Plan

  • Tested locally with yarn dev - markdown files are accessible via .md URLs
  • Verified content cleaning removes JSX/MDX syntax correctly
  • Confirmed build process integration with yarn build
  • Deploy to staging for final verification

🤖 Generated with Claude Code

Implements automatic generation of clean markdown files from MDX sources,
making the docs easily consumable by LLMs and other tools.

Users can now append .md to any documentation URL to get a clean markdown version.

Changes:
- Enhanced generate-llms.js to create individual .md files for each .mdx page
- Integrated markdown generation into the build process via postbuild hook
- Added cleanMdxContent function to strip JSX, imports, and MDX-specific syntax
- Smart output directory selection (out/ for builds, public/ for dev)
- Updated README with feature documentation

Example usage:
https://docs.celestia.org/learn/TIA/overview.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jcstein, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Celestia documentation by adding a mechanism to automatically generate LLM-friendly markdown files from the existing MDX source. This allows users and AI tools to easily consume the documentation in a simplified format. The changes include updates to the build process, a new content cleaning function, and adjustments to the documentation itself to reflect the new feature.

Highlights

  • LLM-Ready Markdown Export: This PR introduces a feature to automatically generate clean markdown files from MDX sources, making the documentation more accessible to Large Language Models (LLMs).
  • .md URL Extension: Users can now append .md to any documentation URL to retrieve a clean markdown version of the page (e.g., https://docs.celestia.org/learn/TIA/overview.md).
  • Automated Generation: The markdown files are generated automatically during the yarn build process, ensuring that the markdown versions are always up-to-date with the documentation.
  • Content Cleaning: The generation process removes JSX components, imports, and MDX-specific syntax, preserving the core documentation content.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • README.md
    • Added a note about the LLM-ready feature and how to access markdown versions of documentation pages.
    • Updated the description of the yarn generate:llms command.
  • package.json
    • Modified the postbuild script to run yarn generate:llms after the build process.
  • scripts/generate-llms.js
    • Added a function cleanMdxContent to remove JSX components, imports, and MDX-specific syntax from the markdown content.
    • Modified the script to generate individual .md files for each .mdx page.
    • Updated the script to output files to the out/ directory during build and public/ during development.
    • Modified the script to generate llms.txt in the appropriate directory (out/ or public/).
Activity
  • The pull request implements the automatic generation of clean markdown files from MDX sources.
  • The pull request allows users to append .md to any documentation URL to get LLM-friendly markdown.
  • The pull request enhances the generate-llms.js script to generate individual .md files for each .mdx page.
  • The pull request integrates markdown generation into the build process.
  • The pull request includes smart content cleaning to remove JSX components, imports, and MDX-specific syntax.
  • The pull request writes output to out/ during build and public/ during development.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

🚀 Preview Deployment

Your preview is ready: https://celestiaorg.github.io/docs-preview/pr-2403/

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a great feature for generating LLM-friendly markdown versions of documentation pages. The implementation is solid, with changes to the build script and process. I've provided a few suggestions in scripts/generate-llms.js to improve code quality and robustness: one to simplify the MDX cleaning logic, another to make path manipulation safer, and a third to reduce code duplication.


// Handle page.mdx files - they should become index.md
if (outputPath.endsWith('/page.md')) {
outputPath = outputPath.replace('/page.md', '.md');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using String.prototype.replace() with a string argument only replaces the first occurrence. If a path contained /page.md earlier in the string (e.g., .../learn/page.md/overview/page.mdx), it could lead to an incorrect output path (.../learn.md/overview/page.md). It's safer to use a regular expression with an end-of-string anchor ($) to ensure you're only replacing the suffix.

      outputPath = outputPath.replace(/\/page\.md$/, '.md');

Comment on lines +9 to +44
function cleanMdxContent(content) {
// Remove frontmatter if present (between --- markers)
const frontmatterRegex = /^---\s*\n[\s\S]*?\n---\s*\n/;
const frontmatterMatch = content.match(frontmatterRegex);
let cleanedContent = content;
let frontmatter = '';

if (frontmatterMatch) {
frontmatter = frontmatterMatch[0];
cleanedContent = content.replace(frontmatterRegex, '');
}

// Remove import statements
cleanedContent = cleanedContent.replace(/^import\s+.*?from\s+['"].*?['"];?\s*$/gm, '');

// Remove export statements (except export default)
cleanedContent = cleanedContent.replace(/^export\s+(?!default).*?;?\s*$/gm, '');

// Remove JSX/React components (custom components starting with capital letters)
cleanedContent = cleanedContent.replace(/<([A-Z][a-zA-Z0-9]*)\s*[^>]*\/>/g, ''); // Self-closing components
cleanedContent = cleanedContent.replace(/<([A-Z][a-zA-Z0-9]*)[^>]*>[\s\S]*?<\/\1>/g, ''); // Component blocks

// Remove MDX-specific syntax like {/* comments */}
cleanedContent = cleanedContent.replace(/\{\/\*[\s\S]*?\*\/\}/g, '');

// Clean up extra whitespace
cleanedContent = cleanedContent.replace(/\n{3,}/g, '\n\n');
cleanedContent = cleanedContent.trim();

// Add frontmatter back if it existed
if (frontmatter) {
return frontmatter + cleanedContent;
}

return cleanedContent;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation of cleanMdxContent preserves the MDX frontmatter. While this might be intentional, frontmatter is not standard Markdown and could be confusing for LLMs. Additionally, the comment on line 10 ("Remove frontmatter...") is misleading as the code actually preserves it. For cleaner, more portable markdown, and simpler code, I suggest removing the frontmatter entirely.

function cleanMdxContent(content) {
  // Remove frontmatter if present (between --- markers)
  let cleanedContent = content.replace(/^---s*\n[\s\S]*?\n---s*\n/, '');

  // Remove import statements
  cleanedContent = cleanedContent.replace(/^import\s+.*?from\s+['"].*?['"];?\s*$/gm, '');

  // Remove export statements (except export default)
  cleanedContent = cleanedContent.replace(/^export\s+(?!default).*?;?\s*$/gm, '');

  // Remove JSX/React components (custom components starting with capital letters)
  cleanedContent = cleanedContent.replace(/<([A-Z][a-zA-Z0-9]*)\s*[^>]*\/>/g, ''); // Self-closing components
  cleanedContent = cleanedContent.replace(/<([A-Z][a-zA-Z0-9]*)[^>]*>[\s\S]*?<\/\1>/g, ''); // Component blocks

  // Remove MDX-specific syntax like {/* comments */}
  cleanedContent = cleanedContent.replace(/{\/\*[\s\S]*?\*\/}/g, '');

  // Clean up extra whitespace
  cleanedContent = cleanedContent.replace(/\n{3,}/g, '\n\n');

  return cleanedContent.trim();
}

console.log(`Found ${files.length} MDX files to convert`);

// Determine output directory - use 'out' if it exists (during build), otherwise 'public' (during dev)
const outputBase = await fs.access('out').then(() => 'out').catch(() => 'public');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to determine outputBase is duplicated in the main function at line 163. To adhere to the DRY (Don't Repeat Yourself) principle and improve maintainability, you could determine outputBase once in the main function and pass it as a parameter to generateMarkdownFiles. This would require changing the signature of generateMarkdownFiles to async (outputBase) and updating the call in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant