|
1 | 1 | import dataclasses |
2 | 2 | import logging |
3 | 3 | import shutil |
4 | | -import typing as t |
5 | 4 | from importlib import resources |
6 | 5 | from importlib.abc import Traversable |
7 | 6 | from pathlib import Path |
8 | 7 |
|
9 | 8 | from markdown import markdown |
10 | 9 |
|
11 | 10 | from cratedb_about import CrateDbKnowledgeOutline |
| 11 | +from cratedb_about.outline import OutlineDocument |
12 | 12 | from cratedb_about.util import get_hostname, get_now |
13 | 13 |
|
14 | 14 | logger = logging.getLogger(__name__) |
|
17 | 17 | @dataclasses.dataclass |
18 | 18 | class LllmsTxtBuilder: |
19 | 19 | """ |
20 | | - Build llms.txt files for CrateDB. |
| 20 | + Generate llms.txt files. |
| 21 | +
|
| 22 | + This is a base class intended to be subclassed. The non-init fields |
| 23 | + (outline, readme_md, outline_yaml) should be initialized by subclasses. |
21 | 24 | """ |
22 | 25 |
|
23 | 26 | outline_url: str |
24 | 27 | outdir: Path |
25 | | - outline: t.Any = dataclasses.field(init=False) |
| 28 | + outline: OutlineDocument = dataclasses.field(init=False) |
26 | 29 | readme_md: Traversable = dataclasses.field(init=False) |
27 | 30 | outline_yaml: Traversable = dataclasses.field(init=False) |
28 | 31 |
|
@@ -71,13 +74,16 @@ def copy_sources(self): |
71 | 74 | str(self.outline_yaml), |
72 | 75 | self.outdir / "outline.yaml", |
73 | 76 | ) |
74 | | - Path(self.outdir / "outline.html").write_text(self.outline.to_html()) |
| 77 | + try: |
| 78 | + Path(self.outdir / "outline.html").write_text(self.outline.to_html()) |
| 79 | + except Exception as e: |
| 80 | + logger.warning(f"Failed to generate HTML outline: {e}") |
75 | 81 |
|
76 | 82 |
|
77 | 83 | @dataclasses.dataclass |
78 | 84 | class CrateDbLllmsTxtBuilder(LllmsTxtBuilder): |
79 | 85 | """ |
80 | | - Build llms.txt files for CrateDB. |
| 86 | + Generate llms.txt files for CrateDB. |
81 | 87 | """ |
82 | 88 |
|
83 | 89 | readme_md: Traversable = resources.files("cratedb_about.bundle") / "readme.md" |
|
0 commit comments