Skip to content

Commit 718b0bc

Browse files
authored
feat: Add base_url config option
PR-25: #25
1 parent ab8caff commit 718b0bc

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ plugins:
6363
- usage/*.md
6464
```
6565

66+
## Override `site_url`
67+
68+
Use `base_url` to point `llms.txt` to documentation in a specific directory. For example, when using [Read the Docs](https://github.com/readthedocs/), use `base_url` to indicate the path to the hosted docs built for a specific language or version.
69+
70+
The resulting `llms.txt` uses `base_url` when it is specified, instead of the canonical `site_url`.
71+
72+
```yaml title="mkdocs.yml"
73+
plugins:
74+
- llmstxt:
75+
base_url: https://productname.hostname.io/en/0.1.34
76+
```
77+
6678
## Full output
6779

6880
Although not explicitly written out in the https://llmstxt.org/ guidelines, it is common to output a `llms-full.txt` file with every page content expanded. This file can be generated by setting the `full_output` configuration value:

src/mkdocs_llmstxt/_internal/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class _PluginConfig(BaseConfig):
1111

1212
autoclean = mkconf.Type(bool, default=True)
1313
preprocess = mkconf.Optional(mkconf.File(exists=True))
14+
base_url = mkconf.Optional(mkconf.Type(str))
1415
markdown_description = mkconf.Optional(mkconf.Type(str))
1516
full_output = mkconf.Optional(mkconf.Type(str))
1617
sections = mkconf.DictOfItems(

src/mkdocs_llmstxt/_internal/plugin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ def on_page_content(self, html: str, *, page: Page, **kwargs: Any) -> str | None
135135
if md_url in (".", "./"):
136136
md_url = ""
137137

138-
# Guaranteed to exist as we require `site_url` to be configured.
139-
base = cast("str", self.mkdocs_config.site_url)
138+
# Use `base_url` if it exists.
139+
if self.config.base_url is not None:
140+
base = cast("str", self.config.base_url)
141+
else: # use a url that is guaranteed to exist as we require `site_url` to be configured.
142+
base = cast("str", self.mkdocs_config.site_url)
140143
if not base.endswith("/"):
141144
base += "/"
142145
md_url = urljoin(base, md_url)

tests/test_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
{
1717
"llmstxt": {
1818
"full_output": "llms-full.txt",
19+
"base_url": "https://example.org/en/0.1.34",
1920
"sections": {
2021
"Index": ["index.md"],
2122
"Usage": [{"page1.md": "Some usage docs."}],

0 commit comments

Comments
 (0)