Add llms.txt config options (#9)

This commit is contained in:
Jared Dillard
2025-05-17 20:22:46 -07:00
committed by GitHub
parent 94a82dc68b
commit 10e2b9a684
7 changed files with 210 additions and 51 deletions
+53 -6
View File
@@ -39,6 +39,7 @@ def test_custom_filename(temp_dir, rootdir):
from sphinx.testing.util import SphinxTestApp
src_dir = rootdir / "basic"
print(src_dir)
# Create a copy of the configuration with a different filename
custom_conf = src_dir / "conf_custom.py"
@@ -46,8 +47,8 @@ def test_custom_filename(temp_dir, rootdir):
conf_content = f.read()
conf_content = conf_content.replace(
'llms_txt_filename = "test-llms-full.txt"',
'llms_txt_filename = "custom-name.txt"',
'llms_txt_full_filename = "test-llms-full.txt"',
'llms_txt_full_filename = "custom-name.txt"',
)
with open(custom_conf, "w") as f:
@@ -59,7 +60,7 @@ def test_custom_filename(temp_dir, rootdir):
builddir=temp_dir,
buildername="html",
freshenv=True,
confoverrides={"llms_txt_filename": "custom-name.txt"},
confoverrides={"llms_txt_full_filename": "custom-name.txt"},
)
app.build()
@@ -94,9 +95,8 @@ def test_max_lines_limit(temp_dir, rootdir):
buildername="html",
freshenv=True,
confoverrides={
"llms_txt_filename": "limited.txt",
"llms_txt_max_lines": 10, # Set a small limit to trigger the warning
"llms_txt_verbose": True,
"llms_txt_full_filename": "limited.txt",
"llms_txt_full_max_size": 10, # Set a small limit to trigger the warning
},
)
@@ -115,3 +115,50 @@ def test_max_lines_limit(temp_dir, rootdir):
# Safe unlink
if hasattr(app, "docutils_conf_path") and app.docutils_conf_path.exists():
app.docutils_conf_path.unlink()
def test_title_override(temp_dir, rootdir):
"""Test that the title override works correctly."""
from sphinx.testing.util import SphinxTestApp
src_dir = rootdir / "basic"
# Custom title to override the default project name
custom_title = "Custom Title Override"
# Create a new test app with the title override
app = SphinxTestApp(
srcdir=src_dir,
builddir=temp_dir,
buildername="html",
freshenv=True,
confoverrides={
"llms_txt_title": custom_title,
},
)
app.build()
# Check if the summary file was created
summary_file = Path(app.outdir) / "llms.txt"
assert summary_file.exists(), f"Summary file {summary_file} does not exist"
# Read the content of the summary file
content = summary_file.read_text()
# Check that the custom title was used
assert (
f"# {custom_title}" in content
), f"Custom title '{custom_title}' not found in summary file"
# Ensure the default project name was NOT used
assert (
"# Test Project" not in content
), "Default project name was used instead of custom title"
# Custom cleanup to avoid missing_ok issue
sys.path[:] = app._saved_path
_clean_up_global_state()
# Safe unlink
if hasattr(app, "docutils_conf_path") and app.docutils_conf_path.exists():
app.docutils_conf_path.unlink()