Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/scripts/merge_quarto_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def merge_items(

def merge_file(base_path: Path, partial_path: Path, key: str) -> None:
base = json.loads(base_path.read_text())
partial = json.loads(partial_path.read_text())
# Quarto only writes listings.json when a rendered page declares a listing,
# so a targeted render of pages that carry none produces no partial index.
# That is a normal outcome, not a failure: nothing changed, nothing to merge.
partial = json.loads(partial_path.read_text()) if partial_path.exists() else []
if not isinstance(base, list) or not isinstance(partial, list):
raise ValueError("Quarto indexes must contain JSON arrays")
partial_path.write_text(
Expand Down
14 changes: 14 additions & 0 deletions .github/scripts/test_merge_quarto_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def test_merge_file_updates_partial_path(self):
],
)

def test_absent_partial_leaves_base_as_the_merged_index(self):
"""A targeted render of pages with no listing writes no partial index."""
with tempfile.TemporaryDirectory() as directory:
base_path = Path(directory) / "base.json"
partial_path = Path(directory) / "partial.json"
base_path.write_text(json.dumps([{"listing": "/old", "items": ["a"]}]))

merge_file(base_path, partial_path, "listing")

self.assertEqual(
json.loads(partial_path.read_text()),
[{"listing": "/old", "items": ["a"]}],
)

def test_missing_key_is_rejected(self):
with self.assertRaises(ValueError):
merge_items([], [{"text": "missing object id"}], "objectID")
Expand Down
Loading