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