← ClaudeAtlas

wechat-publishinglisted

博客文章同步到微信公众号草稿箱。mp 后台 API 直推(Playwright+msedge 登录态,跳过风控),含封面自动化、代码高亮、原文链接注入、内链替换,及 background 简写被过滤等已踩坑位。
xiaoshuai1024/skills · ★ 0 · AI & Automation · score 72
Install: claude install-skill xiaoshuai1024/skills
# 公众号发布 ## 何时用 写完文章并通过 Hugo 构建(`hugo --gc --minify`)后,同步到公众号草稿箱时调用。 ## 方案:mp 后台 API 直推(`publish_mp.py`) 用 Playwright persistent context 持有真实登录态 cookie,通过 `context.request` 直接调 `mp.weixin.qq.com` 的 Web 后台内部 API(与编辑器「保存为草稿」同一接口)。**全程无模拟点击/键盘,不触发前端反自动化埋点**——这是相比 wechatsync 扩展桥接(掉线频繁)、Playwright 模拟点击 ProseMirror(被风控)的第三条路。 入口:`make wechat-publish-mp slug=<slug>`(旧 `make wechat-publish` 走 wechatsync,**已弃用**)。 ## 前置条件 - **msedge 浏览器**:本机 Chrome 安装损坏(SxS 并行配置错误),Playwright 内置 chromium 访问 mp 站必崩(Page crashed)。**所有 Playwright 任务必须 `channel="msedge"`**。 - `wechat-profile/`(gitignore)持久化登录态,首次需扫码;检测登录看 cookie 是否含 `slave_sid`。 - 两套 Python:`.venv`(`prepare` 用,含 `bs4`);全局 Python311(`publish_mp` 用,含 `playwright`)。Makefile 已分别调用,勿混。 - 文章已 `hugo --gc --minify` 构建到 `public/`。 ## 发布流程 ### Step 1: 构建 + 部署博客站 ```bash hugo --gc --minify # 构建到 public/ ./deploy.sh "备注" # 推源码 + 部署 Pages ``` ### Step 2: 准备公众号内容 ```bash make wechat-prepare slug=<slug> ``` `scripts/wechat/prepare.py`(走 `--for-wechatsync` 路径)做的事: 1. 从 `public/posts/<slug>/index.html` 的 `.content` 区提取正文,剔除导航/TOC/分享按钮 2. `clean_and_style()`:注入 inline 样式(公众号不支持 CSS class),清除非 span 标签的 class 3. `convert_images()`:SVG → PNG(公众号不支持 SVG),**首图额外按 9:5 裁出 `cover.png`** 4. `replace_internal_links()`:内链按平台替换(`link-map.json` 已记录的用平台链接,否则回退博客站) 5. **`_process_code_blocks()`**:代码块 `<pre>` → `<section>` + 逐行 `<p>`,Hugo chroma class → Monokai inline 颜色(映射表见下)。**背景色写法见「代码块背景」坑**。 6. 文末注入原文链接段落 7. 按平台生成 `wechat-ready-{weixin,ju