mkdocs-llm-context 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocs_llm_context-0.1.0/.github/dependabot.yml +11 -0
- mkdocs_llm_context-0.1.0/.github/workflows/ci.yml +32 -0
- mkdocs_llm_context-0.1.0/.github/workflows/publish-pypi.yml +29 -0
- mkdocs_llm_context-0.1.0/.gitignore +210 -0
- mkdocs_llm_context-0.1.0/CHANGELOG.md +32 -0
- mkdocs_llm_context-0.1.0/CONTRIBUTING.md +29 -0
- mkdocs_llm_context-0.1.0/LICENSE +21 -0
- mkdocs_llm_context-0.1.0/Makefile +17 -0
- mkdocs_llm_context-0.1.0/PKG-INFO +86 -0
- mkdocs_llm_context-0.1.0/README.md +59 -0
- mkdocs_llm_context-0.1.0/pyproject.toml +54 -0
- mkdocs_llm_context-0.1.0/src/mkdocs_llm_context/__init__.py +5 -0
- mkdocs_llm_context-0.1.0/src/mkdocs_llm_context/plugin.py +63 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/docs/index.md +3 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/docs/other.md +3 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/docs_notitle/index.md +3 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/docs_notitle/notitle.md +1 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/mkdocs.yml +8 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/mkdocs_exclude.yml +10 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/mkdocs_notitle.yml +8 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/mkdocs_txt.yml +10 -0
- mkdocs_llm_context-0.1.0/tests/fixtures/mkdocs_txt_auto.yml +9 -0
- mkdocs_llm_context-0.1.0/tests/test_plugin.py +106 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.9", "3.12"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v6
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v6
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: pip install -e ".[dev]"
|
|
27
|
+
|
|
28
|
+
- name: Lint
|
|
29
|
+
run: python -m ruff check .
|
|
30
|
+
|
|
31
|
+
- name: Test
|
|
32
|
+
run: python -m pytest tests/ -v
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Publish
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-python@v6
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
|
|
22
|
+
- name: Install build
|
|
23
|
+
run: pip install build
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: python -m build
|
|
27
|
+
|
|
28
|
+
- name: Publish to PyPI
|
|
29
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# Test fixture build output
|
|
158
|
+
tests/fixtures/site/
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
#.idea/
|
|
180
|
+
|
|
181
|
+
# Abstra
|
|
182
|
+
# Abstra is an AI-powered process automation framework.
|
|
183
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
184
|
+
# Learn more at https://abstra.io/docs
|
|
185
|
+
.abstra/
|
|
186
|
+
|
|
187
|
+
# Visual Studio Code
|
|
188
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
189
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
190
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
191
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
192
|
+
# .vscode/
|
|
193
|
+
|
|
194
|
+
# Ruff stuff:
|
|
195
|
+
.ruff_cache/
|
|
196
|
+
|
|
197
|
+
# PyPI configuration file
|
|
198
|
+
.pypirc
|
|
199
|
+
|
|
200
|
+
# Cursor
|
|
201
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
202
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
203
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
204
|
+
.cursorignore
|
|
205
|
+
.cursorindexingignore
|
|
206
|
+
|
|
207
|
+
# Marimo
|
|
208
|
+
marimo/_static/
|
|
209
|
+
marimo/_lsp/
|
|
210
|
+
__marimo__/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [Unreleased]
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## [0.1.0] - 2026-02-25
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- `format` option: `json` (list of `{url, title, content}`) or `txt` (single file with `## Title` sections separated by `---`)
|
|
18
|
+
- `output` option: filename written to the MkDocs site directory; auto-derives from `format` when not set
|
|
19
|
+
- `exclude` option: glob patterns matched against `page.url` to omit pages from the bundle
|
|
20
|
+
- Type hints on all plugin methods
|
|
21
|
+
- `ruff` linting in dev toolchain
|
|
22
|
+
- `Makefile` with `install`, `test`, `lint`, `build`, and `clean` targets
|
|
23
|
+
- CI via GitHub Actions (Python 3.9 + 3.12 matrix)
|
|
24
|
+
- Dependabot for pip and GitHub Actions ecosystems
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- Plugin config uses typed `Config` subclass (MkDocs 1.4+ pattern) instead of deprecated `config_scheme` tuple
|
|
28
|
+
- Page content uses `page.markdown` (source markdown) instead of rendering HTML and converting back — output is cleaner and token-efficient
|
|
29
|
+
- Pages with no title fall back to `page.url` instead of producing `null`
|
|
30
|
+
|
|
31
|
+
### Removed
|
|
32
|
+
- `markdownify` dependency (no longer needed)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Contributions are welcome — bug reports, feature requests, and pull requests.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/agibson22/mkdocs-llm-context
|
|
9
|
+
cd mkdocs-llm-context
|
|
10
|
+
python -m venv .venv && source .venv/bin/activate
|
|
11
|
+
make install
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Development workflow
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
make test # run tests
|
|
18
|
+
make lint # run ruff
|
|
19
|
+
make build # build the wheel
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Tests run `mkdocs build` against a minimal fixture under `tests/fixtures/` and assert the output file structure and content. Add a fixture and test for any new config option.
|
|
23
|
+
|
|
24
|
+
## Submitting a pull request
|
|
25
|
+
|
|
26
|
+
1. Fork the repo and create a branch from `main`
|
|
27
|
+
2. Make your changes with tests
|
|
28
|
+
3. Ensure `make lint` and `make test` both pass
|
|
29
|
+
4. Open a pull request with a clear description of the change
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chickadee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.PHONY: install test lint build clean
|
|
2
|
+
|
|
3
|
+
install:
|
|
4
|
+
pip install -e ".[dev]"
|
|
5
|
+
|
|
6
|
+
test:
|
|
7
|
+
python -m pytest tests/ -v
|
|
8
|
+
|
|
9
|
+
lint:
|
|
10
|
+
python -m ruff check .
|
|
11
|
+
|
|
12
|
+
build:
|
|
13
|
+
pip install build --quiet
|
|
14
|
+
python -m build
|
|
15
|
+
|
|
16
|
+
clean:
|
|
17
|
+
rm -rf dist/ .pytest_cache/ src/*.egg-info
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mkdocs-llm-context
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bundle your MkDocs site into a single file for LLM or agent context.
|
|
5
|
+
Project-URL: Homepage, https://github.com/agibson22/mkdocs-llm-context
|
|
6
|
+
Project-URL: Repository, https://github.com/agibson22/mkdocs-llm-context
|
|
7
|
+
Project-URL: Issues, https://github.com/agibson22/mkdocs-llm-context/issues
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai,context,llm,mkdocs,plugin
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Documentation
|
|
20
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: mkdocs>=1.5.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# mkdocs-llm-context
|
|
29
|
+
|
|
30
|
+
[](https://github.com/agibson22/mkdocs-llm-context/actions/workflows/ci.yml)
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
[](https://pypi.org/project/mkdocs-llm-context/)
|
|
33
|
+
|
|
34
|
+
Bundle your MkDocs site into a single file for LLM or agent context.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install mkdocs-llm-context
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Add the plugin to your `mkdocs.yml`:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
plugins:
|
|
48
|
+
- llm-context
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Configuration
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
plugins:
|
|
55
|
+
- llm-context:
|
|
56
|
+
format: json # "json" (default) or "txt"
|
|
57
|
+
output: llm-context.json # default derives from format
|
|
58
|
+
exclude:
|
|
59
|
+
- changelog/
|
|
60
|
+
- api/reference/*
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
| Option | Default | Description |
|
|
64
|
+
|--------|---------|-------------|
|
|
65
|
+
| `format` | `json` | Output format: `json` (list of `{url, title, content}`) or `txt` (sections separated by `---`) |
|
|
66
|
+
| `output` | `llm-context.{format}` | Filename written to the site directory |
|
|
67
|
+
| `exclude` | `[]` | Glob patterns matched against `page.url` — matching pages are omitted |
|
|
68
|
+
|
|
69
|
+
After `mkdocs build`, the file appears in `site/` and can be used as context for an LLM or agent.
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/agibson22/mkdocs-llm-context
|
|
75
|
+
cd mkdocs-llm-context
|
|
76
|
+
python -m venv .venv && source .venv/bin/activate
|
|
77
|
+
make install
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
make test # run tests
|
|
82
|
+
make lint # run ruff
|
|
83
|
+
make build # build the wheel
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# mkdocs-llm-context
|
|
2
|
+
|
|
3
|
+
[](https://github.com/agibson22/mkdocs-llm-context/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://pypi.org/project/mkdocs-llm-context/)
|
|
6
|
+
|
|
7
|
+
Bundle your MkDocs site into a single file for LLM or agent context.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install mkdocs-llm-context
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add the plugin to your `mkdocs.yml`:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
plugins:
|
|
21
|
+
- llm-context
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Configuration
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
plugins:
|
|
28
|
+
- llm-context:
|
|
29
|
+
format: json # "json" (default) or "txt"
|
|
30
|
+
output: llm-context.json # default derives from format
|
|
31
|
+
exclude:
|
|
32
|
+
- changelog/
|
|
33
|
+
- api/reference/*
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Option | Default | Description |
|
|
37
|
+
|--------|---------|-------------|
|
|
38
|
+
| `format` | `json` | Output format: `json` (list of `{url, title, content}`) or `txt` (sections separated by `---`) |
|
|
39
|
+
| `output` | `llm-context.{format}` | Filename written to the site directory |
|
|
40
|
+
| `exclude` | `[]` | Glob patterns matched against `page.url` — matching pages are omitted |
|
|
41
|
+
|
|
42
|
+
After `mkdocs build`, the file appears in `site/` and can be used as context for an LLM or agent.
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/agibson22/mkdocs-llm-context
|
|
48
|
+
cd mkdocs-llm-context
|
|
49
|
+
python -m venv .venv && source .venv/bin/activate
|
|
50
|
+
make install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
make test # run tests
|
|
55
|
+
make lint # run ruff
|
|
56
|
+
make build # build the wheel
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mkdocs-llm-context"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Bundle your MkDocs site into a single file for LLM or agent context."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { text = "MIT" }
|
|
7
|
+
requires-python = ">=3.9"
|
|
8
|
+
keywords = ["mkdocs", "llm", "ai", "context", "plugin"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.9",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Topic :: Documentation",
|
|
19
|
+
"Topic :: Software Development :: Documentation",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
dependencies = [
|
|
23
|
+
"mkdocs>=1.5.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/agibson22/mkdocs-llm-context"
|
|
28
|
+
Repository = "https://github.com/agibson22/mkdocs-llm-context"
|
|
29
|
+
Issues = "https://github.com/agibson22/mkdocs-llm-context/issues"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=7.0.0",
|
|
34
|
+
"ruff>=0.4.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.entry-points."mkdocs.plugins"]
|
|
38
|
+
llm-context = "mkdocs_llm_context.plugin:LlmContextPlugin"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["hatchling"]
|
|
42
|
+
build-backend = "hatchling.build"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/mkdocs_llm_context"]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 100
|
|
49
|
+
|
|
50
|
+
[tool.ruff.lint]
|
|
51
|
+
select = ["E", "F", "I", "UP"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""MkDocs plugin: bundle all pages into one JSON or TXT file for LLM context."""
|
|
2
|
+
|
|
3
|
+
import fnmatch
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from mkdocs.config import config_options as c
|
|
10
|
+
from mkdocs.config.base import Config as MkDocsConfig
|
|
11
|
+
from mkdocs.exceptions import PluginError
|
|
12
|
+
from mkdocs.plugins import BasePlugin
|
|
13
|
+
from mkdocs.structure.pages import Page
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger("mkdocs.plugins.mkdocs_llm_context")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class LlmContextPluginConfig(MkDocsConfig):
|
|
19
|
+
output = c.Optional(c.Type(str))
|
|
20
|
+
format = c.Choice(("json", "txt"), default="json")
|
|
21
|
+
exclude = c.Type(list, default=[])
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class LlmContextPlugin(BasePlugin[LlmContextPluginConfig]):
|
|
25
|
+
"""Bundle the built MkDocs site into a single file (JSON or TXT) for LLM/agent context."""
|
|
26
|
+
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
super().__init__()
|
|
29
|
+
self._pages: list[dict[str, str]] = []
|
|
30
|
+
|
|
31
|
+
def on_pre_build(self, config: MkDocsConfig, **kwargs: Any) -> None:
|
|
32
|
+
"""Clear accumulator so mkdocs serve rebuilds don't duplicate."""
|
|
33
|
+
self._pages = []
|
|
34
|
+
|
|
35
|
+
def on_post_page(self, output: str, page: Page, config: MkDocsConfig, **kwargs: Any) -> None:
|
|
36
|
+
"""Accumulate page source markdown, skipping excluded pages."""
|
|
37
|
+
if any(fnmatch.fnmatch(page.url, pattern) for pattern in self.config.exclude):
|
|
38
|
+
log.debug("Skipping excluded page: %s", page.url)
|
|
39
|
+
return
|
|
40
|
+
title = page.title or page.url
|
|
41
|
+
self._pages.append({"url": page.url, "title": title, "content": page.markdown})
|
|
42
|
+
|
|
43
|
+
def on_post_build(self, config: MkDocsConfig, **kwargs: Any) -> None:
|
|
44
|
+
"""Write accumulated pages to a single output file."""
|
|
45
|
+
site_dir = Path(config["site_dir"])
|
|
46
|
+
out_fmt = self.config.format
|
|
47
|
+
output_name = self.config.output or f"llm-context.{out_fmt}"
|
|
48
|
+
out_path = site_dir / output_name
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
if out_fmt == "json":
|
|
52
|
+
with open(out_path, "w", encoding="utf-8") as f:
|
|
53
|
+
json.dump(self._pages, f, indent=2, ensure_ascii=False)
|
|
54
|
+
else:
|
|
55
|
+
parts = [
|
|
56
|
+
f"## {r['title']}\nURL: {r['url']}\n\n{r['content']}"
|
|
57
|
+
for r in self._pages
|
|
58
|
+
]
|
|
59
|
+
with open(out_path, "w", encoding="utf-8") as f:
|
|
60
|
+
f.write("\n\n---\n\n".join(parts))
|
|
61
|
+
log.info("Wrote %s (%d pages) to %s", output_name, len(self._pages), out_path)
|
|
62
|
+
except OSError as e:
|
|
63
|
+
raise PluginError(f"Failed to write {out_path}: {e}") from e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
No heading here, just content.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Tests for mkdocs-llm-context plugin: run mkdocs build from fixture and assert output."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
FIXTURES_DIR = Path(__file__).resolve().parent / "fixtures"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _build(config_file: Path, site_dir: Path) -> subprocess.CompletedProcess:
|
|
12
|
+
return subprocess.run(
|
|
13
|
+
[
|
|
14
|
+
sys.executable,
|
|
15
|
+
"-m",
|
|
16
|
+
"mkdocs",
|
|
17
|
+
"build",
|
|
18
|
+
"--config-file",
|
|
19
|
+
str(config_file),
|
|
20
|
+
"--site-dir",
|
|
21
|
+
str(site_dir),
|
|
22
|
+
],
|
|
23
|
+
cwd=FIXTURES_DIR,
|
|
24
|
+
capture_output=True,
|
|
25
|
+
text=True,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_plugin_produces_json_output(tmp_path):
|
|
30
|
+
"""Default output is llm-context.json with expected structure."""
|
|
31
|
+
result = _build(FIXTURES_DIR / "mkdocs.yml", tmp_path / "site")
|
|
32
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
33
|
+
|
|
34
|
+
out_file = tmp_path / "site" / "llm-context.json"
|
|
35
|
+
assert out_file.exists(), f"Expected {out_file} to exist"
|
|
36
|
+
|
|
37
|
+
data = json.loads(out_file.read_text(encoding="utf-8"))
|
|
38
|
+
assert isinstance(data, list)
|
|
39
|
+
assert len(data) == 2, "Fixture has two nav pages"
|
|
40
|
+
|
|
41
|
+
for item in data:
|
|
42
|
+
assert {"url", "title", "content"} <= item.keys()
|
|
43
|
+
assert isinstance(item["content"], str)
|
|
44
|
+
|
|
45
|
+
titles = {item["title"] for item in data}
|
|
46
|
+
assert "Home" in titles
|
|
47
|
+
assert "Other" in titles
|
|
48
|
+
|
|
49
|
+
contents = " ".join(item["content"] for item in data)
|
|
50
|
+
assert "Some content" in contents
|
|
51
|
+
assert "More content" in contents
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_json_content_is_source_markdown(tmp_path):
|
|
55
|
+
"""Content field contains raw source markdown, not rendered HTML."""
|
|
56
|
+
result = _build(FIXTURES_DIR / "mkdocs.yml", tmp_path / "site")
|
|
57
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
58
|
+
|
|
59
|
+
data = json.loads((tmp_path / "site" / "llm-context.json").read_text(encoding="utf-8"))
|
|
60
|
+
contents = " ".join(item["content"] for item in data)
|
|
61
|
+
assert "<" not in contents, "Content should be source markdown, not HTML"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_plugin_txt_format_explicit_output(tmp_path):
|
|
65
|
+
"""With format: txt and explicit output name, file is written correctly."""
|
|
66
|
+
result = _build(FIXTURES_DIR / "mkdocs_txt.yml", tmp_path / "site_txt")
|
|
67
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
68
|
+
|
|
69
|
+
out_file = tmp_path / "site_txt" / "llm-context.txt"
|
|
70
|
+
assert out_file.exists()
|
|
71
|
+
text = out_file.read_text(encoding="utf-8")
|
|
72
|
+
assert "## Home" in text
|
|
73
|
+
assert "## Other" in text
|
|
74
|
+
assert "Some content" in text
|
|
75
|
+
assert "More content" in text
|
|
76
|
+
assert "---" in text, "Sections should be separated by ---"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_plugin_txt_format_derives_output_name(tmp_path):
|
|
80
|
+
"""With format: txt and no output set, filename auto-derives to llm-context.txt."""
|
|
81
|
+
result = _build(FIXTURES_DIR / "mkdocs_txt_auto.yml", tmp_path / "site_auto")
|
|
82
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
83
|
+
|
|
84
|
+
assert (tmp_path / "site_auto" / "llm-context.txt").exists()
|
|
85
|
+
assert not (tmp_path / "site_auto" / "llm-context.json").exists()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_page_with_no_title(tmp_path):
|
|
89
|
+
"""Pages with no H1 heading fall back to page.url rather than producing null/None."""
|
|
90
|
+
result = _build(FIXTURES_DIR / "mkdocs_notitle.yml", tmp_path / "site_notitle")
|
|
91
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
92
|
+
|
|
93
|
+
data = json.loads((tmp_path / "site_notitle" / "llm-context.json").read_text(encoding="utf-8"))
|
|
94
|
+
titles = {item["title"] for item in data}
|
|
95
|
+
assert None not in titles, "title should never be null"
|
|
96
|
+
assert all(isinstance(t, str) and t for t in titles), "all titles should be non-empty strings"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_exclude_option(tmp_path):
|
|
100
|
+
"""Pages matching exclude patterns are omitted from the output."""
|
|
101
|
+
result = _build(FIXTURES_DIR / "mkdocs_exclude.yml", tmp_path / "site_exclude")
|
|
102
|
+
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
103
|
+
|
|
104
|
+
data = json.loads((tmp_path / "site_exclude" / "llm-context.json").read_text(encoding="utf-8"))
|
|
105
|
+
assert len(data) == 1, "Only one page should remain after excluding 'other/'"
|
|
106
|
+
assert data[0]["title"] == "Home"
|