|
53 | 53 | # Same fence detection as llmstxt_preprocess.renumber_ordered_lists. |
54 | 54 | _FENCE_OPEN_RE = re.compile(r"^(\s*)(`{3,}|~{3,})") |
55 | 55 |
|
| 56 | +_LLMS_TXT_POINTER_RE = re.compile( |
| 57 | + r"(?m)^> For the complete documentation index, see \[llms\.txt\]\([^)]*\)\.\n\n?" |
| 58 | +) |
| 59 | + |
56 | 60 |
|
57 | 61 | class DocSet(NamedTuple): |
58 | 62 | """One documentation set shipped in the package.""" |
@@ -187,6 +191,11 @@ def _replace(match): |
187 | 191 | return _MD_LINK_RE.sub(_replace, line) |
188 | 192 |
|
189 | 193 |
|
| 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 | + |
190 | 199 | def rewrite_page(content, page_path, docsets, class_paths): |
191 | 200 | """Rewrite a page's links, leaving fenced code blocks untouched.""" |
192 | 201 | lines = content.split("\n") |
@@ -289,12 +298,8 @@ def build(dev_site, dev_plugins, user_site, user_plugins, class_map_path, versio |
289 | 298 | for docset, site in docsets: |
290 | 299 | for page_rel in sorted(docset.pages): |
291 | 300 | 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) |
298 | 303 | llms[docset.root] = rewrite_llms_txt( |
299 | 304 | (site / "llms.txt").read_text(encoding="utf-8"), docset |
300 | 305 | ) |
|
0 commit comments