Skip to content

Commit 4cc2538

Browse files
committed
Remove llms.txt mention
1 parent 5368311 commit 4cc2538

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

build_package_docs.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
# Same fence detection as llmstxt_preprocess.renumber_ordered_lists.
5454
_FENCE_OPEN_RE = re.compile(r"^(\s*)(`{3,}|~{3,})")
5555

56+
_LLMS_TXT_POINTER_RE = re.compile(
57+
r"(?m)^> For the complete documentation index, see \[llms\.txt\]\([^)]*\)\.\n\n?"
58+
)
59+
5660

5761
class DocSet(NamedTuple):
5862
"""One documentation set shipped in the package."""
@@ -187,6 +191,11 @@ def _replace(match):
187191
return _MD_LINK_RE.sub(_replace, line)
188192

189193

194+
def strip_llms_txt_pointer(content):
195+
"""Drop the llmstxt plugin's "see llms.txt" pointer line (see _LLMS_TXT_POINTER_RE)."""
196+
return _LLMS_TXT_POINTER_RE.sub("", content)
197+
198+
190199
def rewrite_page(content, page_path, docsets, class_paths):
191200
"""Rewrite a page's links, leaving fenced code blocks untouched."""
192201
lines = content.split("\n")
@@ -289,12 +298,8 @@ def build(dev_site, dev_plugins, user_site, user_plugins, class_map_path, versio
289298
for docset, site in docsets:
290299
for page_rel in sorted(docset.pages):
291300
page_path = f"{docset.root}/{page_rel}"
292-
rewritten[page_path] = rewrite_page(
293-
(site / page_rel).read_text(encoding="utf-8"),
294-
page_path,
295-
(developer, user),
296-
class_paths,
297-
)
301+
content = strip_llms_txt_pointer((site / page_rel).read_text(encoding="utf-8"))
302+
rewritten[page_path] = rewrite_page(content, page_path, (developer, user), class_paths)
298303
llms[docset.root] = rewrite_llms_txt(
299304
(site / "llms.txt").read_text(encoding="utf-8"), docset
300305
)

tests/python/test_build_package_docs.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
check_relative_doc_links,
44
rewrite_llms_txt,
55
rewrite_page,
6+
strip_llms_txt_pointer,
67
)
78

89
DEVELOPER = DocSet(
@@ -219,6 +220,53 @@ def test_unknown_page_stays_absolute(self):
219220
assert rewrite_llms_txt(content, DEVELOPER) == content
220221

221222

223+
class TestLlmsTxtPointer:
224+
"""Mirrors the shapes inject_page_metadata() (tools/llms_txt/llmstxt_preprocess.py) produces."""
225+
226+
def test_pointer_is_removed_without_leaving_a_double_blank_line(self):
227+
content = (
228+
"# Getting started\n"
229+
"\n"
230+
"> For the complete documentation index, see [llms.txt](https://doc.ibexa.co/en/5.0/llms.txt).\n"
231+
"\n"
232+
"Body text here.\n"
233+
)
234+
assert strip_llms_txt_pointer(content) == "# Getting started\n\nBody text here.\n"
235+
236+
def test_description_and_editions_lines_are_kept(self):
237+
content = (
238+
"# Heading\n"
239+
"\n"
240+
"> For the complete documentation index, see [llms.txt](https://doc.ibexa.co/en/5.0/llms.txt).\n"
241+
"\n"
242+
"Some page description.\n"
243+
"\n"
244+
"Editions: Content, Experience\n"
245+
)
246+
assert strip_llms_txt_pointer(content) == (
247+
"# Heading\n\nSome page description.\n\nEditions: Content, Experience\n"
248+
)
249+
250+
def test_nested_project_url_is_also_stripped(self):
251+
content = (
252+
"# Edit images\n"
253+
"\n"
254+
"> For the complete documentation index, see "
255+
"[llms.txt](https://doc.ibexa.co/projects/userguide/en/5.0/llms.txt).\n"
256+
"\n"
257+
"Body.\n"
258+
)
259+
assert strip_llms_txt_pointer(content) == "# Edit images\n\nBody.\n"
260+
261+
def test_pointer_without_a_heading_is_stripped_cleanly(self):
262+
content = (
263+
"> For the complete documentation index, see [llms.txt](https://doc.ibexa.co/en/5.0/llms.txt).\n"
264+
"\n"
265+
"Just body text.\n"
266+
)
267+
assert strip_llms_txt_pointer(content) == "Just body text.\n"
268+
269+
222270
class TestSelfCheck:
223271
def test_valid_links_pass(self):
224272
pages = {

0 commit comments

Comments
 (0)