Skip to content

Conversation

@fcakyon
Copy link
Member

@fcakyon fcakyon commented Dec 20, 2025

Adds automatic Vercel-style llms.txt file generation after site build.

Generated file: llms.txt (22K tokens vs 49K tokens in Vercel)

ultralytics-mkdocs-llmstxt.mp4

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Adds automatic llms.txt generation after MkDocs builds to make Ultralytics docs easier for LLMs to discover and consume 🤖📚

📊 Key Changes

  • ✅ New plugin option: add_llms_txt (default: True) to control whether llms.txt is generated
  • 🏗️ Added on_post_build() hook to generate llms.txt after the site finishes building
  • 🧩 Implemented generate_llms_txt() in plugin/postprocess.py:
    • Builds a structured list of documentation pages (Vercel-style) using MkDocs nav when available
    • Falls back to scanning all Markdown files if nav isn’t provided
    • Pulls optional page descriptions from Markdown frontmatter (description)
    • Writes the result to site/llms.txt
  • 🔧 Updated standalone postprocess_site() to optionally generate llms.txt via add_llms_txt (default: True)

🎯 Purpose & Impact

  • 🤝 Improves LLM friendliness: provides a single, curated index of docs pages for AI tools and crawlers to reference
  • 🧭 Better structure and discoverability: respects MkDocs navigation order/sections when nav is configured
  • 📝 Richer context: includes per-page descriptions (when present in frontmatter) to help models choose relevant pages
  • ⚙️ Low-risk, opt-out behavior: enabled by default but can be disabled via config if undesired (add_llms_txt: false) ✅

Adds automatic llms.txt file generation after site build with:
- Vercel-style nested structure with ## section headers
- Description extraction from markdown frontmatter
- Uses parent directory name for index.md instead of "Index"
- Parses mkdocs.yml nav for organization
@fcakyon fcakyon self-assigned this Dec 20, 2025
@fcakyon fcakyon requested a review from glenn-jocher December 20, 2025 20:05
@UltralyticsAssistant UltralyticsAssistant added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 20, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @fcakyon, thank you for submitting a ultralytics/mkdocs 🚀 PR! This is an automated message, and an Ultralytics engineer will assist you shortly. 🤖✅

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/mkdocs main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Solid, minimal integration via on_post_build() and a clear add_llms_txt toggle. Main concerns are robustness: generate_llms_txt()’s reliance on site_dir.parent/mkdocs.yml can miss the real config/nav in common build setups, and frontmatter parsing can hard-fail on custom YAML tags. Also consider making URL conversion more path-safe and avoiding unconditional stdout prints during builds.

💬 Posted 4 inline comments

…ng mkdocs.yml

- Add optional site_name, site_description, nav params to generate_llms_txt()
- Pass already-parsed MkDocs config values from on_post_build()
- Fallback to reading mkdocs.yml only in standalone postprocess mode
…ng mkdocs.yml

- Add optional site_name, site_description, nav params to generate_llms_txt()
- Pass already-parsed MkDocs config values from on_post_build()
- Fallback to reading mkdocs.yml only in standalone postprocess mode
- Fix yaml import scope to ensure it's always available for get_description()
- Fix double newlines in llms.txt output
@fcakyon
Copy link
Member Author

fcakyon commented Dec 20, 2025

Recreating with clean git history

@fcakyon fcakyon closed this Dec 20, 2025
@fcakyon fcakyon removed the request for review from glenn-jocher December 20, 2025 21:01
@fcakyon fcakyon deleted the feature/llms-txt-generation branch December 20, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants