#!/bin/bash
# 生成最终 HTML(内联图片,跳过广告相关图片)
python3 - << 'PYEOF'
import os, re, base64
BASE_DIR = "/root/.openclaw/workspaces/yzr-yxl/projects/yu-zhi-ran/content/published/2026-04-14-上海阳台种菜一年"
MD_FILE = os.path.join(BASE_DIR, "final-article-optimized.md")
IMAGES_DIR = os.path.join(BASE_DIR, "images")
OUT_HTML = os.path.join(BASE_DIR, "上海阳台种菜一年_发布版.html")
SKIP_IMAGES = ["08-App截图.png"]
with open(MD_FILE, "r", encoding="utf-8") as f:
content = f.read()
# 预加载图片 base64(排除跳过的)
image_cache = {}
for fname in os.listdir(IMAGES_DIR):
if fname.endswith('.png') and fname not in SKIP_IMAGES:
path = os.path.join(IMAGES_DIR, fname)
with open(path, "rb") as fimg:
image_cache[fname] = base64.b64encode(fimg.read()).decode('utf-8')
# 替换图片
def replace_img(match):
alt, fname = match.groups()
key = os.path.basename(fname)
if key in image_cache:
return f''
else:
return f'
[图片已省略: {alt}]
' content = re.sub(r'!\[(.*?)\]\((images/.*?)\)', replace_img, content) # MD → HTML html_lines = [] for line in content.split('\n'): if line.startswith('# '): html_lines.append(f'{line[2:]}') elif re.match(r'^[-*] ', line): html_lines.append(f'
{tmp}
') html = f'''