Skip to content

Commit 4dff69d

Browse files
committed
refactor: Use public/internal API layout
1 parent 3e643c4 commit 4dff69d

File tree

6 files changed

+24
-20
lines changed

6 files changed

+24
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ def preprocess(soup: BeautifulSoup, output: str) -> None:
7777

7878
The `output` argument lets you modify the soup *depending on which file is being generated*.
7979

80-
Have a look at [our own pre-processing function](https://pawamoy.github.io/mkdocs-llmstxt/reference/mkdocs_llmstxt/preprocess/#mkdocs_llmstxt.preprocess.autoclean) to get inspiration.
80+
Have a look at [our own cleaning function](https://pawamoy.github.io/mkdocs-llmstxt/reference/mkdocs_llmstxt/#mkdocs_llmstxt.autoclean) to get inspiration.

src/mkdocs_llmstxt/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from __future__ import annotations
77

88
from mkdocs_llmstxt._internal.plugin import MkdocsLLMsTxtPlugin
9+
from mkdocs_llmstxt._internal.preprocess import autoclean
910

1011
__all__: list[str] = [
1112
"MkdocsLLMsTxtPlugin",
13+
"autoclean",
1214
]
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
"""Configuration options for the MkDocs LLMsTxt plugin."""
1+
# Configuration options for the MkDocs LLMsTxt plugin.
22

33
from __future__ import annotations
44

55
from mkdocs.config import config_options as mkconf
66
from mkdocs.config.base import Config as BaseConfig
77

88

9-
class FileConfig(BaseConfig):
9+
class _FileConfig(BaseConfig):
1010
"""Sub-config for each Markdown file."""
1111

1212
output = mkconf.Type(str)
1313
inputs = mkconf.ListOfItems(mkconf.Type(str))
1414

1515

16-
class PluginConfig(BaseConfig):
16+
class _PluginConfig(BaseConfig):
1717
"""Configuration options for the plugin."""
1818

1919
autoclean = mkconf.Type(bool, default=True)
2020
preprocess = mkconf.Optional(mkconf.File(exists=True))
21-
files = mkconf.ListOfItems(mkconf.SubConfig(FileConfig))
21+
files = mkconf.ListOfItems(mkconf.SubConfig(_FileConfig))

src/mkdocs_llmstxt/_internal/logger.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Logging functions."""
1+
# Logging functions.
22

33
from __future__ import annotations
44

@@ -9,7 +9,7 @@
99
from collections.abc import MutableMapping
1010

1111

12-
class PluginLogger(logging.LoggerAdapter):
12+
class _PluginLogger(logging.LoggerAdapter):
1313
"""A logger adapter to prefix messages with the originating package name."""
1414

1515
def __init__(self, prefix: str, logger: logging.Logger):
@@ -35,7 +35,7 @@ def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]
3535
return f"{self.prefix}: {msg}", kwargs
3636

3737

38-
def get_logger(name: str) -> PluginLogger:
38+
def _get_logger(name: str) -> _PluginLogger:
3939
"""Return a logger for plugins.
4040
4141
Arguments:
@@ -46,4 +46,4 @@ def get_logger(name: str) -> PluginLogger:
4646
prefixing each message with the plugin package name.
4747
"""
4848
logger = logging.getLogger(f"mkdocs.plugins.{name}")
49-
return PluginLogger(name.split(".", 1)[0], logger)
49+
return _PluginLogger(name.split(".", 1)[0], logger)

src/mkdocs_llmstxt/_internal/plugin.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""MkDocs plugin that generates a Markdown file at the end of the build."""
1+
# MkDocs plugin that generates a Markdown file at the end of the build.
22

33
from __future__ import annotations
44

@@ -16,9 +16,9 @@
1616
from mkdocs.exceptions import PluginError
1717
from mkdocs.plugins import BasePlugin
1818

19-
from mkdocs_llmstxt._internal.config import PluginConfig
20-
from mkdocs_llmstxt._internal.logger import get_logger
21-
from mkdocs_llmstxt._internal.preprocess import autoclean, preprocess
19+
from mkdocs_llmstxt._internal.config import _PluginConfig
20+
from mkdocs_llmstxt._internal.logger import _get_logger
21+
from mkdocs_llmstxt._internal.preprocess import autoclean, _preprocess
2222

2323
if TYPE_CHECKING:
2424
from typing import Any
@@ -28,10 +28,10 @@
2828
from mkdocs.structure.pages import Page
2929

3030

31-
logger = get_logger(__name__)
31+
_logger = _get_logger(__name__)
3232

3333

34-
class MkdocsLLMsTxtPlugin(BasePlugin[PluginConfig]):
34+
class MkdocsLLMsTxtPlugin(BasePlugin[_PluginConfig]):
3535
"""The MkDocs plugin to generate an `llms.txt` file.
3636
3737
This plugin defines the following event hooks:
@@ -44,9 +44,11 @@ class MkdocsLLMsTxtPlugin(BasePlugin[PluginConfig]):
4444
"""
4545

4646
mkdocs_config: MkDocsConfig
47+
"""The global MkDocs configuration."""
4748

4849
def __init__(self) -> None:
4950
self.html_pages: dict[str, dict[str, str]] = defaultdict(dict)
51+
"""Dictionary to store the HTML contents of pages."""
5052

5153
def _expand_inputs(self, inputs: list[str], page_uris: list[str]) -> list[str]:
5254
expanded: list[str] = []
@@ -102,7 +104,7 @@ def on_page_content(self, html: str, *, page: Page, **kwargs: Any) -> str | None
102104
"""
103105
for file in self.config.files:
104106
if page.file.src_uri in file["inputs"]:
105-
logger.debug(f"Adding page {page.file.src_uri} to page {file['output']}")
107+
_logger.debug(f"Adding page {page.file.src_uri} to page {file['output']}")
106108
self.html_pages[file["output"]][page.file.src_uri] = html
107109
return html
108110

@@ -139,11 +141,11 @@ def language_callback(tag: Tag) -> str:
139141
if self.config.autoclean:
140142
autoclean(soup)
141143
if self.config.preprocess:
142-
preprocess(soup, self.config.preprocess, file["output"])
144+
_preprocess(soup, self.config.preprocess, file["output"])
143145

144146
output_file = Path(config.site_dir).joinpath(file["output"])
145147
output_file.parent.mkdir(parents=True, exist_ok=True)
146148
markdown = mdformat.text(converter.convert_soup(soup), options={"wrap": "no"})
147149
output_file.write_text(markdown, encoding="utf8")
148150

149-
logger.info(f"Generated file /{file['output']}")
151+
_logger.info(f"Generated file /{file['output']}")

src/mkdocs_llmstxt/_internal/preprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""HTML pre-processing."""
1+
# HTML pre-processing.
22

33
from __future__ import annotations
44

@@ -28,7 +28,7 @@ def _load_module(module_path: str) -> ModuleType:
2828
raise RuntimeError("Spec or loader is null")
2929

3030

31-
def preprocess(soup: Soup, module_path: str, output: str) -> None:
31+
def _preprocess(soup: Soup, module_path: str, output: str) -> None:
3232
"""Pre-process HTML with user-defined functions.
3333
3434
Parameters:

0 commit comments

Comments
 (0)