Files
hoelee-blog/scripts/update_frontmatter_assets.py
T

45 lines
1.5 KiB
Python

import os
import re
repo = "D:/dev/hoelee-blog"
posts_dir = os.path.join(repo, "src/content/posts")
slugs = [
("when-lowering-crf-does-nothing-maxrate-deadlock", False),
("why-ffmpeg-map-0-breaks-your-mp4-and-mkv-remux", False),
("traefik-yaegi-plugin-package-name-trap", True),
("architecting-sea-payment-and-offline-licensing-pipelines", True),
("batch-generating-80-technical-covers-with-comfyui", True)
]
for slug, is_draft in slugs:
en_path = os.path.join(posts_dir, f"{slug}.md")
zh_path = os.path.join(posts_dir, "zh", f"{slug}.md")
draft_val = "true" if is_draft else "false"
# Process EN
with open(en_path, "r", encoding="utf-8") as f:
en_text = f.read()
en_text = re.sub(r"^draft:\s*(true|false)", f"draft: {draft_val}", en_text, flags=re.MULTILINE)
if "ogImage:" not in en_text:
en_text = re.sub(r"^---\r?\n", f"---\nogImage: \"/og/{slug}.jpg\"\nbanner: \"/banners/{slug}.jpg\"\n", en_text)
with open(en_path, "w", encoding="utf-8") as f:
f.write(en_text)
# Process ZH
with open(zh_path, "r", encoding="utf-8") as f:
zh_text = f.read()
zh_text = re.sub(r"^draft:\s*(true|false)", f"draft: {draft_val}", zh_text, flags=re.MULTILINE)
if "ogImage:" not in zh_text:
zh_text = re.sub(r"^---\r?\n", f"---\nogImage: \"/og/zh-{slug}.jpg\"\nbanner: \"/banners/{slug}.jpg\"\n", zh_text)
with open(zh_path, "w", encoding="utf-8") as f:
f.write(zh_text)
print("Frontmatter updated successfully.")