Files
blog/scripts/migrate/moments_migrate.py
wait4xandGLM-5.3 aea21c8694 feat(migrate): Halo 全量内容迁移(压缩版)——6文/21图/1瞬间 URL 1:1
- 正文源=线上渲染页(Halo 快照层 patch 残迹:泥潭/赎罪仅 2 字符),
  pandoc html→gfm + tags API 显示名换算后分类:5 书评(五档情绪色)+1 技术
- 图库 21 张:长边 2400/q86 压缩入仓(原图 196M→9.5M——公开仓历史膨胀
  与 nginx 100M 推送上限双杀;原图在 Phase 0 备份 tar 中永久留档)
- 瞬间 1 条;URL 1:1(6 slug 全等,零 301)
- 本提交由 7 个本地提交重写而成(清除已进历史的 196M blob,未推送过);
  因 reset --soft 暂存竞态,一并包含 spec 归档文件
  (.spec/specs/archive/2026-10-24_migrate-blog-content/)

验证: check_urls.py 6==6;astro build 11 页 exit 0(8.67s);
      EXIF 管线跑通;staging 更新;halo healthy+200 全程未动

Co-authored-by: GLM-5.3
2026-10-25 00:39:08 +08:00

53 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""瞬间迁移(Phase 2 T4):Halo moments → content/moments/*.md
Halo moment.content.html 为富文本(内联样式很脏),经 pandoc 提纯为
纯文本 md;medium(配图)当前库存为空,字段留待将来有图时扩展。
"""
import json
import subprocess
from datetime import datetime, timezone
from pathlib import Path
OUT = Path("content/moments")
def main() -> int:
moments = json.load(open(".migration/moments.json", encoding="utf-8"))
n = 0
for m in moments:
spec = m["spec"]
if spec.get("visible") == "PRIVATE":
continue
html = (spec.get("content") or {}).get("html", "")
text = subprocess.run(
["/home/wait4x/.local/bin/pandoc", "-f", "html", "-t", "plain", "--wrap=none"],
input=html.encode(), capture_output=True, check=True,
).stdout.decode("utf-8").strip()
if not text:
continue
ts = spec.get("releaseTime") or m["metadata"].get("creationTimestamp", "")
day = datetime.fromisoformat(ts.replace("Z", "+00:00")).astimezone(timezone.utc).strftime("%Y-%m-%d")
out = OUT / f"{day}.md"
i = 2
while out.exists():
out = OUT / f"{day}-{i}.md"
i += 1
tags = spec.get("tags") or []
# schema 约束 text/image 在 frontmatter(body 不参与校验),一句话即 text 字段
out.write_text(
"---\n"
f"pubDate: {day}\n"
f"tags: [{', '.join(tags)}]\n"
f'text: "{text.replace(chr(34), chr(39))}"\n'
"---\n",
encoding="utf-8",
)
n += 1
print(f"migrated {n} moments")
return 0
if __name__ == "__main__":
raise SystemExit(main())