scripts...

This commit is contained in:
ed committed 2026-08-24 09:50:29 -04:00
1 parent 6deb7e3bcb
commit 866b5f7245
4 files changed
+52 -18

No files matched your search

+18 -6
View File
@@ -278,6 +278,23 @@ def _upsert_wikilink(path: Path, target: str) -> None:
"""
text = path.read_text(encoding="utf-8")
fm, body = _split_frontmatter(text)
if not fm.strip():
# Frontmatter got nuked by a hand edit. Don't silently emit a
# bare wikilink list — fall back to a fresh standard frontmatter
# so the file remains a complete page.
handle = path.parent.name
fm = (
f"---\n"
f"title: {handle}\n"
f"type: note\n"
f"draft: false\n"
f"description: Archived threads by {handle}.\n"
f"tags:\n"
f" - archive\n"
f" - twitter\n"
f" - {handle}\n"
f"---\n"
)
kept: list[str] = []
names: list[str] = []
handle_dir = path.parent
@@ -286,8 +303,6 @@ def _upsert_wikilink(path: Path, target: str) -> None:
match = _WIKILINK_ITEM.match(line)
if match:
name = match.group(1)
# Drop stale wikilinks whose folder no longer exists under
# this handle. Same-slug duplicates still get collapsed.
if name in real_dirs or not real_dirs:
if name not in names:
names.append(name)
@@ -307,10 +322,7 @@ def _upsert_wikilink(path: Path, target: str) -> None:
parts.extend(f"- [[{name}]]" for name in names)
parts.append("")
body_text = "\n".join(parts)
if fm:
path.write_text(fm.rstrip() + "\n\n" + body_text, encoding="utf-8", newline="\n")
else:
path.write_text(body_text, encoding="utf-8", newline="\n")
path.write_text(fm.rstrip() + "\n\n" + body_text, encoding="utf-8", newline="\n")
def wiki_thread(handle: str, dir_name: str) -> str:
+20 -3
View File
@@ -259,6 +259,7 @@ def cmd_sync(handle: str | None) -> int:
root = VAULT / "archive" / "threads"
targets = [root / handle] if handle else None
changed = 0
skipped = 0
for handle_dir in targets or sorted(root.iterdir()):
if not handle_dir.is_dir() or handle_dir.name.startswith("."):
continue
@@ -268,8 +269,24 @@ def cmd_sync(handle: str | None) -> int:
text = idx.read_text(encoding="utf-8")
end = text.find("\n---", 3)
if end < 0:
continue
fm = text[: end + 4]
# Frontmatter isn't closed — fall back to a fresh one rather
# than silently skipping.
fm = (
f"---\n"
f"title: {handle_dir.name}\n"
f"type: note\n"
f"draft: false\n"
f"description: Archived threads by {handle_dir.name}.\n"
f"tags:\n"
f" - archive\n"
f" - twitter\n"
f" - {handle_dir.name}\n"
f"---\n"
)
skipped += 1
print(f"rebuilt frontmatter for {handle_dir.name}")
else:
fm = text[: end + 4]
dirs = sorted(d.name for d in handle_dir.iterdir() if d.is_dir())
links = "\n".join(f"- [[archive/threads/{handle_dir.name}/{d}]]" for d in dirs)
new = fm + "\n\n" + links + "\n"
@@ -279,7 +296,7 @@ def cmd_sync(handle: str | None) -> int:
print(f"rewrote {handle_dir.name}: {len(dirs)} dirs")
else:
print(f"ok {handle_dir.name}: {len(dirs)} dirs")
print(f"changed {changed}")
print(f"changed {changed}, skipped {skipped}")
return 0