### Setup Development Environment with Make Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet shows how to set up the development environment for the mkdocs-llmstxt project by navigating to the project directory and running the 'setup' command using 'make'. It also provides an alternative method using 'uv sync' if 'make setup' fails, and mentions the 'uv' installer. ```bash cd mkdocs-llmstxt make setup ``` ```bash curl -LsSf https://astral.sh/uv/install.sh | sh # Then try running `make setup` again, or simply `uv sync`. ``` -------------------------------- ### Install mkdocs-llmstxt Plugin Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Installs the mkdocs-llmstxt Python package using pip. This is the primary step to enable the plugin's functionality within an MkDocs project. ```bash pip install mkdocs-llmstxt ``` -------------------------------- ### Generate /llms.txt Content Example Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Example of the generated /llms.txt content based on the mkdocs.yml configuration. It includes site name, description, and organized sections with links to Markdown files. ```markdown # My project > Description of my project. Long description of my project. ## Usage documentation - [File1 title](https://myproject.com/file1.md): Description of file1 - [File2 title](https://myproject.com/file2.md) ``` -------------------------------- ### Complete mkdocs.yml Configuration for llmstxt Plugin Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt An example mkdocs.yml file showcasing all available options for the llmstxt plugin. This configuration includes enabling autoclean, specifying a custom preprocessing script, overriding the site_url, defining the full output file name, providing a markdown description, and structuring documentation sections. ```yaml # mkdocs.yml site_name: My Awesome Library site_description: A Python library for awesome things. site_url: https://awesome-lib.io/ plugins: - search - mkdocstrings: handlers: python: paths: [src] - llmstxt: autoclean: true # Enable HTML cleanup (default) preprocess: scripts/llms_preprocess.py # Custom preprocessing base_url: https://awesome-lib.io/en/stable/ # Override site_url full_output: llms-full.txt # Generate expanded output markdown_description: | My Awesome Library provides utilities for processing and transforming data. Key features: - Fast data processing with async support - Extensible plugin architecture - Comprehensive type annotations sections: Getting Started: - index.md: Overview and quick start guide - installation.md: Installation instructions for all platforms User Guide: - guide/basics.md: Basic usage patterns - guide/advanced.md: Advanced configuration - guide/plugins.md: Writing custom plugins API Reference: - reference/*.md # All API documentation pages Examples: - examples/simple.md: Simple usage example - examples/advanced.md: Advanced usage patterns ``` -------------------------------- ### Generated llms.txt Output Format Example Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt An example of the structured `llms.txt` file generated by the mkdocs-llmstxt plugin. This format adheres to the llmstxt.org specification, including site title, description, markdown description, and organized sections with links to documentation pages. ```markdown # My Awesome Library > A Python library for awesome things. My Awesome Library provides utilities for processing and transforming data. Key features: - Fast data processing with async support - Extensible plugin architecture - Comprehensive type annotations ## Getting Started - [Overview](https://awesome-lib.io/en/stable/index.md): Overview and quick start guide - [Installation](https://awesome-lib.io/en/stable/installation.md): Installation instructions for all platforms ## User Guide - [Basic Usage](https://awesome-lib.io/en/stable/guide/basics.md): Basic usage patterns - [Advanced Configuration](https://awesome-lib.io/en/stable/guide/advanced.md): Advanced configuration - [Custom Plugins](https://awesome-lib.io/en/stable/guide/plugins.md): Writing custom plugins ## API Reference - [Core API](https://awesome-lib.io/en/stable/reference/core.md) - [Utils API](https://awesome-lib.io/en/stable/reference/utils.md) ## Examples - [Simple Example](https://awesome-lib.io/en/stable/examples/simple.md): Simple usage example - [Advanced Example](https://awesome-lib.io/en/stable/examples/advanced.md): Advanced usage patterns ``` -------------------------------- ### Testing Plugin Configuration with pytest and MkDocs API Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt An example test case demonstrating how to programmatically test the behavior of the mkdocs-llmstxt plugin using pytest and the MkDocs build API. This approach allows for automated verification of plugin functionality within a testing environment. ```python ... ``` -------------------------------- ### Python Pre-processing Function Example Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Example of a Python script for pre-processing HTML with the llmstxt plugin. The 'preprocess' function accepts 'soup' (BeautifulSoup object) and 'output' (filename) arguments to modify the HTML structure. ```python from typing import TYPE_CHECKING if TYPE_CHECKING: from bs4 import BeautifulSoup def preprocess(soup: BeautifulSoup, output: str) -> None: ... # modify the soup ``` -------------------------------- ### Test llms.txt Generation (Python) Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Tests the generation of the 'llms.txt' and 'llms-full.txt' files by the mkdocs-llmstxt plugin. It calls the build function with the configured MkDocs setup and asserts the existence and content of the generated files, ensuring they contain the expected site name, description, and content snippets. ```python def test_llmstxt_generation(mkdocs_config: MkDocsConfig) -> None: """Test that llms.txt is correctly generated.""" build(config=mkdocs_config) site_dir = Path(mkdocs_config.site_dir) # Check llms.txt exists and has correct content llmstxt = site_dir / "llms.txt" assert llmstxt.exists() content = llmstxt.read_text() assert "# Test Site" in content assert "Test project description." in content assert "Usage documentation" in content # Check full output exists llms_full = site_dir / "llms-full.txt" assert llms_full.exists() full_content = llms_full.read_text() assert "Usage guide content." in full_content # Check individual markdown files index_md = site_dir / "index.md" assert index_md.exists() assert "Main page content." in index_md.read_text() ``` -------------------------------- ### MkdocsLLMsTxtPlugin Class for MkDocs Integration Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt The main Python class for the mkdocs-llmstxt plugin, designed to integrate with MkDocs event hooks for generating the llms.txt file. This example shows how to programmatically instantiate and use the plugin's event handlers, such as `on_config`, `on_page_content`, and `on_post_build`, potentially for testing or custom build pipelines. ```python from mkdocs.config.defaults import MkDocsConfig from mkdocs.plugins import BasePlugin from mkdocs_llmstxt import MkdocsLLMsTxtPlugin # The plugin is typically used via mkdocs.yml configuration, but can be # programmatically instantiated for testing or custom build pipelines class CustomPlugin(BasePlugin): """Example of extending or wrapping the llmstxt plugin.""" def __init__(self): self.llmstxt_plugin = MkdocsLLMsTxtPlugin() def on_config(self, config: MkDocsConfig) -> MkDocsConfig: # Plugin validates that site_url is set # Raises ValueError if site_url is None return self.llmstxt_plugin.on_config(config) def on_page_content(self, html: str, page, **kwargs) -> str: # Plugin converts HTML to Markdown for pages in sections return self.llmstxt_plugin.on_page_content(html, page=page, **kwargs) def on_post_build(self, config: MkDocsConfig, **kwargs) -> None: # Plugin writes llms.txt and individual .md files self.llmstxt_plugin.on_post_build(config=config, **kwargs) ``` -------------------------------- ### Git Commit Message Convention Example Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet illustrates the structure of a commit message according to the Angular or Karma convention. It shows the format with type, scope, subject, body, and optional trailers for issue and PR references. ```git [(scope)]: Subject [Body] Issue #10: https://github.com/namespace/project/issues/10 Related to PR namespace/other-project#15: https://github.com/namespace/other-project/pull/15 ``` -------------------------------- ### Development Workflow: Building and Previewing Documentation Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet details the process for building and previewing the project's documentation after updating documentation or dependencies. It involves running 'make docs' and then accessing the local documentation server at http://localhost:8000. ```bash make docs # Then go to http://localhost:8000 and check that everything looks good ``` -------------------------------- ### Running Project Tasks with Make Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet demonstrates how to interact with the project's tasks and commands using the 'make' utility. It suggests running 'make' to list available commands and highlights the distinction between commands and tasks, with tasks requiring Python dependencies. ```bash make ``` -------------------------------- ### Create MkDocs Configuration Fixture (Python) Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt A pytest fixture to create a minimal MkDocs configuration for testing. It sets up a temporary directory, creates sample markdown files, and configures the mkdocs-llmstxt plugin with specific options like 'full_output', 'markdown_description', and 'sections'. ```python from pathlib import Path from textwrap import dedent import pytest from mkdocs.commands.build import build from mkdocs.config.defaults import MkDocsConfig @pytest.fixture def mkdocs_config(tmp_path: Path) -> MkDocsConfig: """Create a minimal MkDocs configuration for testing.""" docs_dir = tmp_path / "docs" docs_dir.mkdir() # Create test pages (docs_dir / "index.md").write_text("# Welcome\n\nMain page content.") (docs_dir / "guide.md").write_text("# Guide\n\nUsage guide content.") config = MkDocsConfig() config.load_dict({ "site_name": "Test Site", "site_url": "https://test.example.com/", "docs_dir": str(docs_dir), "site_dir": str(tmp_path / "site"), "plugins": [{ "llmstxt": { "full_output": "llms-full.txt", "markdown_description": "Test project description.", "sections": { "Home": ["index.md"], "Documentation": [{"guide.md": "Usage documentation"}], }, }, }], }) return config ``` -------------------------------- ### Using autoclean Function in Custom Scripts Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Illustrates how to import and utilize the `autoclean` function within custom preprocessing scripts. This allows applying the plugin's default cleanup logic before implementing custom modifications. ```python # Example usage within a custom preprocessing script: # from mkdocs_llmstxt.plugin import autoclean # # def preprocess(soup, output): # autoclean(soup) # # Add custom modifications here ``` -------------------------------- ### Development Workflow: Formatting, Checking, and Testing Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet outlines the essential steps to perform before committing code changes in the mkdocs-llmstxt project. It includes running 'make format' for auto-formatting, 'make check' for linting and checks, and 'make test' for running unit tests. ```bash make format make check make test ``` -------------------------------- ### Basic Plugin Configuration in mkdocs.yml Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Enables the llmstxt plugin and defines markdown description and sections for content inclusion in the generated llms.txt file. Requires a site_url to be set. ```yaml # mkdocs.yml site_name: My Project site_description: A comprehensive project documentation. site_url: https://myproject.com/ # Required for the llmstxt plugin plugins: - llmstxt: markdown_description: > My Project is a Python library for processing data. It provides utilities for parsing, transforming, and exporting datasets. sections: Getting Started: - index.md: Main documentation page - installation.md: How to install the library Usage Guide: - usage/basics.md: Basic usage examples - usage/advanced.md: Advanced configuration options API Reference: - reference/api.md: Complete API documentation ``` -------------------------------- ### Using Glob Patterns for File Selection in mkdocs.yml Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Demonstrates how to use glob patterns within the plugin configuration to automatically include multiple Markdown files based on specified patterns. This is useful for managing large documentation sets. ```yaml # mkdocs.yml plugins: - llmstxt: sections: Tutorials: - tutorials/*.md # Matches all .md files in tutorials/ API Reference: - reference/**/*.md # Recursively matches all .md files in reference/ Guides: - guides/getting-started.md: Introduction guide - guides/deployment/*.md # All deployment guides ``` -------------------------------- ### Configure mkdocs-llmstxt Plugin in mkdocs.yml Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Enables and configures the llmstxt plugin in the mkdocs.yml configuration file. It requires 'site_name', 'site_description', and 'site_url'. Optional parameters like 'markdown_description' and 'sections' allow for detailed content organization. ```yaml site_name: My project site_description: Description of my project. site_url: https://myproject.com/ # Required for the llmstxt plugin to work. plugins: - llmstxt: markdown_description: Long description of my project. sections: Usage documentation: - file1.md: Description of file1 - file2.md # Descriptions are optional. ``` -------------------------------- ### Enable Full Output Generation in mkdocs.yml Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Configures the llmstxt plugin to generate a 'llms-full.txt' file containing the expanded content of all pages. This is achieved by setting the 'full_output' configuration value. ```yaml plugins: - llmstxt: full_output: llms-full.txt sections: Usage documentation: - index.md - usage/*.md ``` -------------------------------- ### Generating Full Output File in mkdocs.yml Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Configures the plugin to generate an expanded `llms-full.txt` file that contains all page content inline. This is beneficial for LLMs that prefer a single, comprehensive document. ```yaml # mkdocs.yml plugins: - llmstxt: full_output: llms-full.txt # Generate expanded version sections: Usage Documentation: - index.md - usage/*.md API Reference: - reference/api.md ``` -------------------------------- ### Custom HTML Preprocessing Script Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Defines a Python script to perform custom HTML preprocessing before Markdown conversion. The script receives a BeautifulSoup object and the output file path, allowing fine-grained control over content modification. ```python # scripts/llms_preprocess.py from typing import TYPE_CHECKING if TYPE_CHECKING: from bs4 import BeautifulSoup def preprocess(soup: BeautifulSoup, output: str) -> None: """Custom preprocessing for llms.txt generation. Args: soup: BeautifulSoup object containing the HTML to process. output: Path to the output Markdown file being generated. """ # Remove all navigation elements for nav in soup.find_all("nav"): nav.decompose() # Remove elements with specific classes for element in soup.find_all(class_="no-llms"): element.decompose() # Modify content based on output file if "api" in output: # Keep code examples for API docs pass else: # Remove code blocks from non-API pages for code in soup.find_all("pre"): code.decompose() # Remove footer elements for footer in soup.find_all("footer"): footer.decompose() ``` -------------------------------- ### Configure HTML Pre-processing Script in mkdocs.yml Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Configures the llmstxt plugin to use a custom Python script for pre-processing HTML before it's converted to Markdown. The 'preprocess' option specifies the path to the script. ```yaml plugins: - llmstxt: preprocess: path/to/script.py ``` -------------------------------- ### Configure mkdocs-llmstxt with File Globbing Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Enables the llmstxt plugin and configures it to use file globbing for including multiple Markdown files within a section. This simplifies the inclusion of numerous documentation files. ```yaml plugins: - llmstxt: sections: Usage documentation: - index.md: Main documentation page - usage/*.md ``` -------------------------------- ### Git Interactive Rebase for Squashing Commits Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet shows how to perform an interactive rebase in Git to squash commits, often used after creating fixup commits. It uses the '--autosquash' option with 'git rebase -i' to automatically handle the squashing process. ```bash git rebase -i --autosquash main ``` -------------------------------- ### Git Fixup Commit for Code Review Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet demonstrates how to create a 'fixup' commit in Git, which is used to amend a previous commit based on review feedback. It shows the command to create a fixup commit for a specific commit SHA. ```bash # SHA is the SHA of the commit you want to fix git commit --fixup=SHA ``` -------------------------------- ### Override site_url with base_url in mkdocs.yml Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Configures the llmstxt plugin to use a 'base_url' instead of the default 'site_url'. This is useful for specifying a canonical URL for documentation hosted in specific directories, such as on Read the Docs. ```yaml plugins: - llmstxt: base_url: https://productname.hostname.io/en/0.1.34 ``` -------------------------------- ### Custom Preprocessing Script for mkdocs-llmstxt Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt A Python script to perform custom preprocessing on HTML content before it's processed by the llmstxt plugin. It utilizes BeautifulSoup for HTML parsing and the autoclean function from mkdocs_llmstxt. This script demonstrates how to remove specific HTML elements like custom admonitions and data attributes. ```python from bs4 import BeautifulSoup from mkdocs_llmstxt import autoclean def preprocess(soup: BeautifulSoup, output: str) -> None: """Apply default cleanup plus custom modifications.""" # Apply default autoclean first autoclean(soup) # Then add custom cleanup # Remove custom admonition types for admonition in soup.find_all("div", class_="admonition"): if "internal-note" in admonition.get("class", []): admonition.decompose() # Remove specific data attributes for element in soup.find_all(attrs={"data-internal": True}): element.decompose() ``` -------------------------------- ### Overriding Base URL in mkdocs.yml Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Specifies a custom `base_url` for generated links within the `llms.txt` file. This is crucial for hosting versioned documentation, such as on Read the Docs. ```yaml # mkdocs.yml site_url: https://myproject.readthedocs.io/ plugins: - llmstxt: base_url: https://myproject.readthedocs.io/en/v2.0.0/ # Version-specific URL sections: Documentation: - index.md - changelog.md ``` -------------------------------- ### Git Force Push After Rebasing Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/CONTRIBUTING.md This snippet demonstrates how to force push changes to a remote repository after performing a rebase operation, such as squashing commits. This is necessary because rebasing rewrites commit history. ```bash git push -f ``` -------------------------------- ### Disabling Auto-Clean in mkdocs.yml Source: https://context7.com/pawamoy/mkdocs-llmstxt/llms.txt Disables the automatic HTML cleanup process performed by the plugin. This option allows preservation of specific HTML elements like images, SVGs, and permalinks that would otherwise be removed. ```yaml # mkdocs.yml plugins: - llmstxt: autoclean: false # Keep all HTML elements sections: Documentation: - index.md ``` -------------------------------- ### Disable HTML Auto-cleaning in mkdocs.yml Source: https://github.com/pawamoy/mkdocs-llmstxt/blob/main/README.md Disables the automatic cleaning of HTML output before it is converted to Markdown by the llmstxt plugin. This is controlled by the 'autoclean' configuration option. ```yaml plugins: - llmstxt: autoclean: false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.