Files
yu-zhi-ran/scripts/clean_published_html.py
lt 277b13eaae feat: 完成布局优化 - 操作列固定、批量按钮自适应、分类标签带数量
优化内容:
1. 表格布局:
   - 使用 calc(100vw - 160px) 确保表格不超出视口
   - 操作列 fixed='right' 固定在右侧,宽度 300px
   - 按钮 3 个后自动换行 (max-width: 200px)
   - 恢复合理列宽,不再过度压缩

2. 批量操作区域:
   - 容器改为 inline-block,宽度自适应按钮内容
   - 背景宽度与按钮总宽度匹配

3. 分类标签:
   - 显示数量 (如 '待处理 (20)')
   - 点击切换筛选,去掉误导的 'X' 图标

4. 删除功能:
   - 操作列增加删除按钮
   - 删除前弹出确认对话框

5. 系统日志:
   - 修复后端日志路径 (parents[4])
   - 404 时显示友好提示

6. 其他:
   - 左侧菜单宽度 160px
   - 所有功能保留 (登录、用户管理、批量操作等)
2026-04-27 11:32:17 +08:00

50 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
"""
清理已发布的 HTML 文件:
1. 删除所有 <img> 标签
2. 清理标题中的 (约XXX字) 括号
"""
import re
from pathlib import Path
files = [
"automation/data/releases/2026-04-21/zhihu/zhihu_TOPIC-BBB1CC_zhihu.html",
"automation/data/releases/2026-04-21/wechat/wechat_TOPIC-BBB1CC_wechat.html",
"automation/data/releases/2026-04-21/xiaohongshu/xiaohongshu_TOPIC-BBB1CC_xiaohongshu.html"
]
def clean_html(html: str) -> str:
# 1. 删除所有 <img ...> 标签
html = re.sub(r'<img[^>]*>', '', html)
# 2. 清理标题中的 (约XXX字) 等括号内容
def clean_text(text: str) -> str:
text = re.sub(r'[(]约\s*\d+字[)]', '', text)
text = re.sub(r'[(]MVP[)]', '', text)
text = re.sub(r'[(][^)]*?[)]', '', text) # 保守移除任意括号内容
return text.strip()
# 处理 <title> 标签
def clean_title(match):
return match.group(1) + clean_text(match.group(2)) + match.group(3)
html = re.sub(r'(<title>)([^<]*)(</title>)', clean_title, html)
# 处理内容中的标题标签 (h1-h6)
def clean_heading(match):
return match.group(1) + clean_text(match.group(2)) + match.group(3)
html = re.sub(r'(<h[1-6][^>]*>)([^<]*)(</h[1-6]>)', clean_heading, html)
return html
if __name__ == "__main__":
for f in files:
path = Path(f)
if not path.exists():
print(f"跳过(不存在): {f}")
continue
original = path.read_text(encoding='utf-8')
cleaned = clean_html(original)
path.write_text(cleaned, encoding='utf-8')
print(f"✅ 已清理: {f}")
print("全部完成!")