Fix issue when source_suffix equals source_link_suffix (#29)
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
0.3.1
|
||||
-----
|
||||
|
||||
- Fix issue when ``source_suffix`` equals ``source_link_suffix``
|
||||
`#29 <https://github.com/jdillard/sphinx-llms-txt/pull/29>`_
|
||||
|
||||
0.3.0
|
||||
-----
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from .manager import LLMSFullManager
|
||||
from .processor import DocumentProcessor
|
||||
from .writer import FileWriter
|
||||
|
||||
__version__ = "0.3.0"
|
||||
__version__ = "0.3.1"
|
||||
|
||||
# Export classes needed by tests
|
||||
__all__ = [
|
||||
|
||||
@@ -90,7 +90,13 @@ class DocumentCollector:
|
||||
|
||||
# Try to find the source file with any of the valid source suffixes
|
||||
for src_suffix in source_suffixes:
|
||||
candidate_file = sources_dir / f"{docname}{src_suffix}{source_link_suffix}"
|
||||
# Avoid duplicate extensions when source_suffix == source_link_suffix
|
||||
if src_suffix == source_link_suffix:
|
||||
candidate_file = sources_dir / f"{docname}{src_suffix}"
|
||||
else:
|
||||
candidate_file = (
|
||||
sources_dir / f"{docname}{src_suffix}{source_link_suffix}"
|
||||
)
|
||||
if candidate_file.exists():
|
||||
return src_suffix
|
||||
|
||||
|
||||
@@ -138,13 +138,22 @@ class LLMSFullManager:
|
||||
|
||||
# Build the source file path directly using the known suffix
|
||||
if src_suffix:
|
||||
source_file = sources_dir / f"{docname}{src_suffix}{source_link_suffix}"
|
||||
# Avoid duplicate extensions when source_suffix == source_link_suffix
|
||||
if src_suffix == source_link_suffix:
|
||||
source_file = sources_dir / f"{docname}{src_suffix}"
|
||||
expected_suffix = src_suffix
|
||||
else:
|
||||
source_file = (
|
||||
sources_dir / f"{docname}{src_suffix}{source_link_suffix}"
|
||||
)
|
||||
expected_suffix = f"{src_suffix}{source_link_suffix}"
|
||||
|
||||
if source_file.exists():
|
||||
docname_to_file[docname] = source_file
|
||||
else:
|
||||
logger.warning(
|
||||
f"sphinx-llms-txt: Source file not found for: {docname}."
|
||||
f"Expected: {docname}{src_suffix}{source_link_suffix}"
|
||||
f"Expected: {docname}{expected_suffix}"
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
@@ -205,6 +214,10 @@ class LLMSFullManager:
|
||||
source_suffixes = self._get_source_suffixes()
|
||||
all_source_files = []
|
||||
for src_suffix in source_suffixes:
|
||||
# Avoid duplicate extensions when source_suffix == source_link_suffix
|
||||
if src_suffix == source_link_suffix:
|
||||
glob_pattern = f"**/*{src_suffix}"
|
||||
else:
|
||||
glob_pattern = f"**/*{src_suffix}{source_link_suffix}"
|
||||
all_source_files.extend(sources_dir.glob(glob_pattern))
|
||||
|
||||
@@ -231,7 +244,12 @@ class LLMSFullManager:
|
||||
|
||||
# Try each source suffix to find which one this file uses
|
||||
for src_suffix in source_suffixes:
|
||||
# Avoid duplicate extensions when suffixes match
|
||||
if src_suffix == source_link_suffix:
|
||||
combined_suffix = src_suffix
|
||||
else:
|
||||
combined_suffix = f"{src_suffix}{source_link_suffix}"
|
||||
|
||||
if rel_path.endswith(combined_suffix):
|
||||
docname = rel_path[: -len(combined_suffix)] # Remove suffix
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user