Skip to content

Commit 2fc46b4

Browse files
committed
Normalize Obsidian log formatting
1 parent f8ddbcd commit 2fc46b4

3 files changed

Lines changed: 85 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The format is inspired by Keep a Changelog, and version tags follow the reposito
2727
- GitHub cards now use the exact repository name as the note title, student-learning sections, repository-specific summaries, method checkpoints, branch tags, and category links instead of generic web-page sentence ranking
2828
- Knowledge-card notes no longer dump full raw content for high-confidence web / GitHub captures; folded evidence is only shown for lower-confidence fallback cases or transcript-style media
2929
- Obsidian knowledge indexes now insert new cards under the correct date heading instead of appending entries into the wrong day block
30+
- Obsidian `_log.md` now uses the same date-grouped one-line entry style as `_index.md`, so historical notes and new ingest logs stay readable
3031
- README and `.env.example` now clarify that Feishu is unsupported and that `auto` output switches to Obsidian as soon as a vault path is configured
3132

3233
## [2.4.0] - 2026-04-19

scripts/process_share_links.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,31 +3653,34 @@ def update_obsidian_log(
36533653
items: list[dict[str, object]],
36543654
generated_at: datetime,
36553655
) -> None:
3656-
"""追加一条操作记录到 log.md,格式可 grep。"""
3656+
"""Append legacy digest-mode log lines grouped by date."""
36573657
log_path = vault_root.expanduser() / obsidian_folder / "_log.md"
3658-
statuses = []
3658+
entries: list[str] = []
36593659
for item in items:
3660-
p = str(item.get("platform_key") or "web")
3661-
s = str(item.get("status") or "unknown")
3662-
t = str(item.get("title") or "未命名")[:60]
3663-
statuses.append(f" - {p} | {s} | {t}")
3664-
entry = (
3665-
f"## [{generated_at.strftime('%Y-%m-%d')}] ingest | {report_title[:80]}\n"
3666-
+ "\n".join(statuses)
3667-
+ "\n\n"
3668-
)
3660+
title = shorten(str(item.get("title") or report_title or "未命名"), 72)
3661+
platform = str(item.get("platform") or item.get("platform_key") or "未知平台")
3662+
status = str(item.get("status") or "unknown")
3663+
entries.append(
3664+
f"- {generated_at.strftime('%H:%M')} · ingest · {title} · {platform} · {status}"
3665+
)
3666+
if not entries:
3667+
return
3668+
3669+
date_heading = f"## {generated_at.strftime('%Y-%m-%d')}"
36693670
if log_path.exists():
3670-
content = log_path.read_text(encoding="utf-8")
3671-
log_path.write_text(content + entry, encoding="utf-8")
3671+
upsert_markdown_date_section_entries(log_path, date_heading, entries)
36723672
else:
36733673
header = (
36743674
"---\n"
36753675
"type: content-log\n"
36763676
f"created: {generated_at.isoformat(timespec='seconds')}\n"
36773677
"---\n\n"
36783678
"# 操作日志\n\n"
3679+
"记录 content-processor 每次入库或结构调整,便于回看导入时间、来源和状态。\n\n"
3680+
"---\n\n"
3681+
f"{date_heading}\n\n"
36793682
)
3680-
log_path.write_text(header + entry, encoding="utf-8")
3683+
log_path.write_text(header + "\n".join(entries).rstrip() + "\n", encoding="utf-8")
36813684

36823685

36833686
def update_obsidian_knowledge_log(
@@ -3690,31 +3693,34 @@ def update_obsidian_knowledge_log(
36903693
) -> None:
36913694
obsidian_root = build_obsidian_folder_root(vault_root, obsidian_folder)
36923695
log_path = obsidian_root / "_log.md"
3693-
statuses = []
3696+
entries: list[str] = []
36943697
for note_path, item in zip(note_paths, items):
36953698
title = str(item.get("knowledge_card_title") or item.get("title") or note_path.stem)
3696-
statuses.append(
3697-
" - "
3699+
platform = str(item.get("platform") or item.get("platform_key") or "未知平台")
3700+
status = str(item.get("status") or "unknown")
3701+
entries.append(
3702+
f"- {generated_at.strftime('%H:%M')} · ingest · "
36983703
+ f"{build_obsidian_wikilink(note_path, vault_root, title)}"
3699-
+ f" | {item.get('platform_key') or 'web'} | {item.get('status') or 'unknown'}"
3704+
+ f" · {platform} · {status}"
37003705
)
3701-
entry = (
3702-
f"## [{generated_at.strftime('%Y-%m-%d')}] ingest | {report_title[:80]}\n"
3703-
+ "\n".join(statuses)
3704-
+ "\n\n"
3705-
)
3706+
if not entries:
3707+
return
3708+
3709+
date_heading = f"## {generated_at.strftime('%Y-%m-%d')}"
37063710
if log_path.exists():
3707-
content = log_path.read_text(encoding="utf-8")
3708-
log_path.write_text(content + entry, encoding="utf-8")
3711+
upsert_markdown_date_section_entries(log_path, date_heading, entries)
37093712
else:
37103713
header = (
37113714
"---\n"
37123715
"type: content-log\n"
37133716
f"created: {generated_at.isoformat(timespec='seconds')}\n"
37143717
"---\n\n"
37153718
"# 操作日志\n\n"
3719+
"记录 content-processor 每次入库或结构调整,便于回看导入时间、来源和状态。\n\n"
3720+
"---\n\n"
3721+
f"{date_heading}\n\n"
37163722
)
3717-
log_path.write_text(header + entry, encoding="utf-8")
3723+
log_path.write_text(header + "\n".join(entries).rstrip() + "\n", encoding="utf-8")
37183724

37193725

37203726
def derive_report_title(cli_title: str | None, items: list[dict[str, object]]) -> str:

tests/test_process_share_links.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,58 @@ def test_update_obsidian_knowledge_index_groups_entries_by_date_heading(self) ->
10541054
self.assertIn("## 2026-04-21", content)
10551055
self.assertIn("NousResearch/hermes-agent", content)
10561056

1057+
def test_update_obsidian_knowledge_log_groups_entries_by_date_heading(self) -> None:
1058+
generated_at = MODULE.datetime(2026, 4, 21, 17, 23)
1059+
with tempfile.TemporaryDirectory() as tmp:
1060+
vault_root = Path(tmp) / "Vault"
1061+
obsidian_folder = "Inbox/内容摘要"
1062+
obsidian_root = vault_root / "Inbox" / "内容摘要"
1063+
obsidian_root.mkdir(parents=True, exist_ok=True)
1064+
log_path = obsidian_root / "_log.md"
1065+
log_path.write_text(
1066+
"\n".join([
1067+
"---",
1068+
"type: content-log",
1069+
"created: 2026-04-20T13:46:25",
1070+
"---",
1071+
"",
1072+
"# 操作日志",
1073+
"",
1074+
"记录 content-processor 每次入库或结构调整,便于回看导入时间、来源和状态。",
1075+
"",
1076+
"---",
1077+
"",
1078+
"## 2026-04-20",
1079+
"",
1080+
"- 19:22 · ingest · [[旧卡片]] · 抖音 · success",
1081+
"",
1082+
]),
1083+
encoding="utf-8",
1084+
)
1085+
note_path = obsidian_root / "2026-04-21" / "run" / "NousResearch_hermes-agent.md"
1086+
note_path.parent.mkdir(parents=True, exist_ok=True)
1087+
note_path.write_text("# hermes\n", encoding="utf-8")
1088+
1089+
MODULE.update_obsidian_knowledge_log(
1090+
vault_root,
1091+
obsidian_folder,
1092+
"NousResearch/hermes-agent",
1093+
[note_path],
1094+
[{
1095+
"knowledge_card_title": "NousResearch/hermes-agent",
1096+
"platform": "GitHub",
1097+
"status": "success",
1098+
}],
1099+
generated_at,
1100+
)
1101+
1102+
content = log_path.read_text(encoding="utf-8")
1103+
1104+
self.assertIn("## 2026-04-20", content)
1105+
self.assertIn("## 2026-04-21", content)
1106+
self.assertIn("17:23 · ingest", content)
1107+
self.assertIn("NousResearch/hermes-agent", content)
1108+
10571109

10581110
if __name__ == "__main__":
10591111
unittest.main()

0 commit comments

Comments
 (0)