Remove get_and_resolve_toctree method (#19)

This commit is contained in:
Jared Dillard
2025-05-20 01:08:40 -07:00
committed by GitHub
parent 9ae05c6c13
commit 70defd3996
2 changed files with 27 additions and 17 deletions
+26 -13
View File
@@ -65,20 +65,33 @@ class DocumentCollector:
):
for child_docname in self.env.toctree_includes[docname]:
collect_from_toctree(child_docname)
else:
# Fallback: try to resolve and parse the toctree
toctree = self.env.get_and_resolve_toctree(docname, None)
if toctree:
from docutils import nodes
for node in list(toctree.findall(nodes.reference)):
if "refuri" in node.attributes:
refuri = node.attributes["refuri"]
if refuri and refuri.endswith(".html"):
child_docname = refuri[:-5] # Remove .html
# Try to use dependencies to find related documents
elif (
hasattr(self.env, "dependencies")
and docname in self.env.dependencies
):
# Extract the dependent documents from the dependencies dict
for child_docname in self.env.dependencies[docname]:
# Only add documents actually in the document set
if (
child_docname != docname
): # Avoid circular references
hasattr(self.env, "all_docs")
and child_docname in self.env.all_docs
):
collect_from_toctree(child_docname)
# Fallback to titles or other available references
elif hasattr(self.env, "titles") and hasattr(self.env, "all_docs"):
# Get all document names
all_docnames = list(self.env.all_docs.keys())
# Look for documents that might be related (have similar paths)
current_prefix = "/".join(docname.split("/")[:-1])
if current_prefix:
for child_docname in all_docnames:
# Documents in the same directory might be related
if (
child_docname.startswith(current_prefix)
and child_docname != docname
):
collect_from_toctree(child_docname)
except Exception as e:
logger.debug(f"Could not get toctree for {docname}: {e}")
-3
View File
@@ -129,9 +129,6 @@ class LLMSFullManager:
if source_file.exists():
docname_to_file[docname] = source_file
logger.debug(
f"sphinx-llms-txt: Found source file for {docname} at {source_file}"
)
else:
logger.warning(
f"sphinx-llm-txt: Source file not found for: {docname}. Expected"