公众号撰文排版 Skill
触发条件
当用户需要以下任一能力时使用本 skill:
- 撰写公众号文案(按风格分类输出)
- 秀米图文排版(HTML/SVG 组件排版)
- 自动化发表公众号内容(无官方接口,走浏览器自动化)
- 直接在微信公众平台编辑(mpHelper):绕过秀米,直接登录 mp.weixin.qq.com 新建图文,填标题/作者/正文并保存草稿
- 自学习入库(learn):把定稿产出或主动导入的 Word/HTML/网页/Markdown 资料的文案与排版风格结构化解析,暂存并经确认后并入
write_style.md/design.md
依赖
- Python 3.8+
- Playwright:
python -m pip install -r requirements.txt后执行python -m playwright install chromium - 登录态(两条发布路径各自独立采集):
- 秀米路径:首次运行
scripts/collect_login.py采集到xiumi_auth.json - 微信直接编辑路径:首次运行
scripts/collect_mp_login.py采集到mp_auth.json(微信 Cookie 时效较短,失效需重扫)
- 秀米路径:首次运行
排版路径二选一
- 秀米排版路径(xiumiHelper):design.md → inject_layout.py 生成 layout.html → xiumi_auto.py 注入秀米并保存
- 微信直接编辑路径(mpHelper):跳过秀米,mp_auto.py 直接登录微信公众平台填入标题/作者/正文并保存草稿
使用流程
- 撰文:读取
write_style.md选择风格 → 按writer.md产出文案 - 排版(可选):读取
design.md规范 → 用scripts/inject_layout.py组件库生成整页 HTML 落盘为layout.html(入口build_page(spec, blocks);微信路径请用wechat_layout()或build_page(wechat=True)生成纯 CSS 卡片版,因微信会清洗 SVG 并降级 h/table/blockquote,用法见脚本 docstring) - 注入保存:选择目标平台
- 秀米:运行
python scripts/xiumi_auto.py --title "标题" --html-file layout.html(可先加--no-save演练,用build_page()生成的 SVG/HTML 版) - 微信直接编辑:运行
python scripts/mp_auto.py --title "标题" --html-file layout.html保存草稿(正文请用 wechat_layout 生成的纯 CSS 卡片版,保存后请在浏览器人工核查)
- 秀米:运行
命令示例
# 秀米路径:注入排版并保存
python scripts/xiumi_auto.py --title "标题" --html-file layout.html
# 秀米路径:直接输入纯文本正文(多段用字面反斜杠 n 分隔)
python scripts/xiumi_auto.py --title "标题" --text "第一段\n第二段"
# 秀米路径:演练模式,只注入不保存
python scripts/xiumi_auto.py --title "标题" --html-file layout.html --no-save
# 微信直接编辑路径:采集微信登录态(扫码,一次即可)
python scripts/collect_mp_login.py
# 微信直接编辑路径:新建图文并保存草稿
python scripts/mp_auto.py --title "标题" --author "作者" --html-file layout.html
# 微信直接编辑路径:直接输纯文本正文
python scripts/mp_auto.py --title "标题" --text "第一段\n第二段"
# 微信直接编辑路径:演练模式,只注入不保存
python scripts/mp_auto.py --title "标题" --html-file layout.html --no-save
# 生成排版 HTML(inject_layout.py 的 build_page 入口,秀米路线的 SVG/HTML 组件)
python -c "from scripts.inject_layout import build_page; open('layout.html','w',encoding='utf-8').write(build_page())"
# 生成微信兼容版排版 HTML(build_page(wechat=True) / wechat_layout(),纯 CSS 卡片,供 mp_auto.py 注入微信)
python -c "from scripts.inject_layout import wechat_layout; open('layout.html','w',encoding='utf-8').write(wechat_layout('标题'))"
脚本说明
| 脚本 | 用途 |
|---|---|
scripts/collect_login.py |
采集秀米登录态到 xiumi_auth.json |
scripts/xiumi_auto.py |
秀米核心自动化:填标题、输正文或注入 HTML、保存图文 |
scripts/collect_mp_login.py |
采集微信公众平台登录态到 mp_auth.json(扫码) |
scripts/mp_auto.py |
微信直接编辑核心自动化:新建图文、填标题/作者/正文、保存草稿 |
scripts/inject_layout.py |
HTML/SVG 排版组件库,供生成排版内容调用 |
scripts/fetch_component.py |
抓取公众号固定页头/页尾:--preview 生成预览确认 → --group 命名 --commit 入库 ~/.gzh-content/components/(可多组,同名防覆盖) |
目录结构
gzh-content/
├── SKILL.md # 本文件(skill 定义)
├── README.md # 项目总览
├── LICENSE # MIT 许可
├── .gitignore # 忽略登录态/临时产物
├── write_style.md # 文案风格分类库
├── design.md # 排版设计规范
├── writer.md # writer 能力说明
├── xiumiHelper.md # xiumiHelper 能力说明(秀米排版路径)
├── mpHelper.md # mpHelper 能力说明(微信直接编辑路径)
├── learn.md # learn 自学习能力说明(用户数据在 ~/.gzh-content/,含路径一/路径二/可复用片段库)
├── requirements.txt # Python 依赖
└── scripts/
├── collect_login.py # 秀米登录态采集
├── xiumi_auto.py # 秀米核心自动化
├── collect_mp_login.py # 微信公众平台登录态采集
├── mp_auto.py # 微信直接编辑核心自动化
├── fetch_component.py # 抓取公众号固定页头/页尾入库 ~/.gzh-content/components/(先预览后命名)
└── inject_layout.py # HTML/SVG 组件库
说明:用户学习数据(
~/.gzh-content/learned/、~/.gzh-content/components/)存放在用户主目录,与 skill 本体分离;skill 重克隆不影响用户积累,用户使用也不改动 skill 结构。