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
+2 -2
View File
@@ -15,8 +15,8 @@ html_theme = "alabaster"
html_static_path = ["_static"]
# Configuration for sphinx-llms-txt
llms_txt_filename = "test-llms-full.txt"
llms_txt_verbose = True
llms_txt_full_filename = "test-llms-full.txt"
llms_txt_file = True
# Master document
master_doc = "index"
+2 -2
View File
@@ -15,8 +15,8 @@ html_theme = "alabaster"
html_static_path = ["_static"]
# Configuration for sphinx-llms-txt
llms_txt_filename = "custom-name.txt"
llms_txt_verbose = True
llms_txt_full_filename = "custom-name.txt"
llms_txt_file = True
# Master document
master_doc = "index"
+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()
+47 -3
View File
@@ -58,9 +58,9 @@ def test_set_config():
"""Test setting configuration."""
manager = LLMSFullManager()
config = {
"llms_txt_filename": "custom.txt",
"llms_txt_verbose": True,
"llms_txt_max_lines": 1000,
"llms_txt_full_filename": "custom.txt",
"llms_txt_file": True,
"llms_txt_full_max_size": 1000,
}
manager.set_config(config)
assert manager.config == config
@@ -175,3 +175,47 @@ def test_process_includes_with_relative_paths(tmp_path):
" directory.\nLine after include."
)
assert processed_content == expected_content
def test_write_verbose_info_to_file(tmp_path):
"""Test writing verbose info to a file."""
# Create a manager
manager = LLMSFullManager()
# Set up a build directory
build_dir = tmp_path / "build"
build_dir.mkdir()
# Set the outdir on the manager
manager.outdir = str(build_dir)
# Set configuration with verbose_file enabled
config = {
"llms_txt_file": True,
"llms_txt_full_max_size": 1000,
"llms_txt_filename": "llms.txt",
}
manager.set_config(config)
# Add some page titles
manager.update_page_title("index", "Home Page")
manager.update_page_title("about", "About Us")
# Create a page order
page_order = ["index", "about"]
# Call the method to write verbose info to file
manager._write_verbose_info_to_file(page_order, 500)
# Check that the file was created
verbose_file = build_dir / "llms.txt"
assert verbose_file.exists()
# Read the file content
with open(verbose_file, "r", encoding="utf-8") as f:
content = f.read()
# Check that the content contains expected information
assert "## Docs" in content
assert "- [Home Page](/index.html)" in content
assert "- [About Us](/about.html)" in content