This commit is contained in:
ed committed 2026-08-26 22:42:09 -04:00
1 parent 3d07098bd0
commit 93be2b9b6a
3 files changed
+45 -15

No files matched your search

+23 -1
View File
@@ -488,7 +488,7 @@ def _upsert_wikilink(path: Path, target: str) -> None:
kept.append(line)
if target not in names:
names.append(target)
names.sort()
names.sort(key=str.lower)
while kept and kept[0] == "":
kept.pop(0)
while kept and kept[-1] == "":
@@ -657,6 +657,28 @@ def ensure_threads_index(vault: Path, handle: str) -> None:
_upsert_wikilink(path, f"archive/threads/{handle}")
def rewrite_threads_index(vault: Path) -> bool:
"""Re-sort the top-level archive/threads/index.md wikilinks alphabetically (case-insensitive).
Preserves frontmatter and prose. Idempotent. No-op if the file is missing
or if no real handle dirs exist.
"""
path = vault / "archive" / "threads" / "index.md"
if not path.is_file():
return False
threads_root = path.parent
real_handles = sorted(
(d.name for d in threads_root.iterdir() if d.is_dir() and not d.name.startswith(".")),
key=str.lower,
)
if not real_handles:
return False
# Pick the first real handle as a no-op upsert target so the existing
# _upsert_wikilink re-sort path runs.
_upsert_wikilink(path, f"archive/threads/{real_handles[0]}")
return True
def discover_dumps(root: Path) -> list[Path]:
"""Return the sorted list of dump subdirectories that contain ``thread_data.json``."""
dumps = [
+8
View File
@@ -48,6 +48,7 @@ try:
format_reslug_plan,
plan_relabel,
plan_reslug,
rewrite_threads_index,
)
from fallback_media import activate_fallback, find_existing_fallback, restore_origin
from media_audit import audit_thread
@@ -63,6 +64,7 @@ except ImportError: # pragma: no cover - script-mode import
format_reslug_plan,
plan_relabel,
plan_reslug,
rewrite_threads_index,
)
from fallback_media import activate_fallback, find_existing_fallback, restore_origin
from media_audit import audit_thread
@@ -755,6 +757,12 @@ def cmd_sync(args: argparse.Namespace) -> int:
print(f"rewrote {handle_dir.name}: {len(dirs)} dirs")
else:
print(f"ok {handle_dir.name}: {len(dirs)} dirs")
# Re-sort the top-level handle list whenever sync runs without a target
# handle. Per-handle indexes (above) are sorted in-place; the top-level
# needs a separate call because its bullet list is not a per-handle file.
if not handle:
if rewrite_threads_index(VAULT):
print("rewrote top-level threads index")
print(f"changed {changed}, skipped {skipped}")
return 0