baoyu-post-to-wechat

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Post to WeChat Official Account

发布到微信公众号

Language

语言

Match user's language: Respond in the same language the user uses. If user writes in Chinese, respond in Chinese. If user writes in English, respond in English.
匹配用户语言:使用用户输入的语言回复。如果用户使用中文书写,请用中文回复;如果用户使用英文书写,请用英文回复。

Script Directory

脚本目录

Agent Execution: Determine this SKILL.md directory as
{baseDir}
, then use
{baseDir}/scripts/<name>.ts
. Resolve
${BUN_X}
runtime: if
bun
installed →
bun
; if
npx
available →
npx -y bun
; else suggest installing bun.
ScriptPurpose
scripts/wechat-browser.ts
Image-text posts (图文)
scripts/wechat-article.ts
Article posting via browser (文章)
scripts/wechat-api.ts
Article posting via API (文章)
scripts/md-to-wechat.ts
Markdown → WeChat-ready HTML with image placeholders
scripts/check-permissions.ts
Verify environment & permissions
Agent执行:将此SKILL.md所在目录判定为
{baseDir}
,随后使用
{baseDir}/scripts/<name>.ts
。解析
${BUN_X}
运行时:如果已安装
bun
则使用
bun
;如果可用
npx
则使用
npx -y bun
;否则建议用户安装bun。
脚本用途
scripts/wechat-browser.ts
图文发布
scripts/wechat-article.ts
通过浏览器发布文章
scripts/wechat-api.ts
通过API发布文章
scripts/md-to-wechat.ts
将Markdown转换为带图片占位符的微信兼容HTML
scripts/check-permissions.ts
验证环境与权限

Preferences (EXTEND.md)

偏好配置(EXTEND.md)

Check EXTEND.md existence (priority order):
bash
undefined
按优先级顺序检查EXTEND.md是否存在:
bash
undefined

macOS, Linux, WSL, Git Bash

macOS, Linux, WSL, Git Bash

test -f .baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo "project" test -f "${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "xdg" test -f "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "user"

```powershell
test -f .baoyu-skills/baoyu-post-to-wechat/EXTEND.md && echo "project" test -f "${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "xdg" test -f "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md" && echo "user"

```powershell

PowerShell (Windows)

PowerShell (Windows)

if (Test-Path .baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { "project" } $xdg = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME/.config" } if (Test-Path "$xdg/baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "xdg" } if (Test-Path "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "user" }

┌────────────────────────────────────────────────────────┬───────────────────┐
│                          Path                          │     Location      │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-post-to-wechat/EXTEND.md           │ Project directory │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md     │ User home         │
└────────────────────────────────────────────────────────┴───────────────────┘

┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│  Result   │                                  Action                                   │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found     │ Read, parse, apply settings                                               │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Run first-time setup ([references/config/first-time-setup.md](references/config/first-time-setup.md)) → Save → Continue │
└───────────┴───────────────────────────────────────────────────────────────────────────┘

**EXTEND.md Supports**: Default theme | Default color | Default publishing method (api/browser) | Default author | Default open-comment switch | Default fans-only-comment switch | Chrome profile path

First-time setup: [references/config/first-time-setup.md](references/config/first-time-setup.md)

**Minimum supported keys** (case-insensitive, accept `1/0` or `true/false`):

| Key | Default | Mapping |
|-----|---------|---------|
| `default_author` | empty | Fallback for `author` when CLI/frontmatter not provided |
| `need_open_comment` | `1` | `articles[].need_open_comment` in `draft/add` request |
| `only_fans_can_comment` | `0` | `articles[].only_fans_can_comment` in `draft/add` request |

**Recommended EXTEND.md example**:

```md
default_theme: default
default_color: blue
default_publish_method: api
default_author: 宝玉
need_open_comment: 1
only_fans_can_comment: 0
chrome_profile_path: /path/to/chrome/profile
Theme options: default, grace, simple, modern
Color presets: blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange (or hex value)
Value priority:
  1. CLI arguments
  2. Frontmatter
  3. EXTEND.md (account-level → global-level)
  4. Skill defaults
if (Test-Path .baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { "project" } $xdg = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME/.config" } if (Test-Path "$xdg/baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "xdg" } if (Test-Path "$HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md") { "user" }

┌────────────────────────────────────────────────────────┬───────────────────┐
│                          路径                          │        位置       │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-post-to-wechat/EXTEND.md           | 项目目录           │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md     │ 用户根目录         │
└────────────────────────────────────────────────────────┴───────────────────┘

┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│  检测结果   |                                  操作                                   │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到文件   │ 读取、解析并应用配置                                                      │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到文件 | 运行首次设置流程 ([references/config/first-time-setup.md](references/config/first-time-setup.md)) → 保存配置 → 继续执行 |
└───────────┴───────────────────────────────────────────────────────────────────────────┘

**EXTEND.md支持配置项**:默认主题 | 默认颜色 | 默认发布方式(api/browser) | 默认作者 | 默认开启评论开关 | 默认仅粉丝评论开关 | Chrome配置文件路径

首次设置指南:[references/config/first-time-setup.md](references/config/first-time-setup.md)

**最低支持配置项**(不区分大小写,接受`1/0`或`true/false`取值):

| 配置项 | 默认值 | 映射关系 |
|-----|---------|---------|
| `default_author` | 空 | 当CLI/文章头未提供作者时的默认 fallback |
| `need_open_comment` | `1` | `draft/add` 请求中的 `articles[].need_open_comment` 字段 |
| `only_fans_can_comment` | `0` | `draft/add` 请求中的 `articles[].only_fans_can_comment` 字段 |

**推荐EXTEND.md示例**:

```md
default_theme: default
default_color: blue
default_publish_method: api
default_author: 宝玉
need_open_comment: 1
only_fans_can_comment: 0
chrome_profile_path: /path/to/chrome/profile
主题选项:default, grace, simple, modern
颜色预设:blue, green, vermilion, yellow, purple, sky, rose, olive, black, gray, pink, red, orange(也可使用十六进制色值)
配置值优先级
  1. CLI参数
  2. 文章头配置
  3. EXTEND.md(账号级别 → 全局级别)
  4. 工具默认值

Multi-Account Support

多账号支持

EXTEND.md supports managing multiple WeChat Official Accounts. When
accounts:
block is present, each account can have its own credentials, Chrome profile, and default settings.
Compatibility rules:
ConditionModeBehavior
No
accounts
block
Single-accountCurrent behavior, unchanged
accounts
with 1 entry
Single-accountAuto-select, no prompt
accounts
with 2+ entries
Multi-accountPrompt to select before publishing
accounts
with
default: true
Multi-accountPre-select default, user can switch
Multi-account EXTEND.md example:
md
default_theme: default
default_color: blue

accounts:
  - name: 宝玉的技术分享
    alias: baoyu
    default: true
    default_publish_method: api
    default_author: 宝玉
    need_open_comment: 1
    only_fans_can_comment: 0
    app_id: your_wechat_app_id
    app_secret: your_wechat_app_secret
  - name: AI工具集
    alias: ai-tools
    default_publish_method: browser
    default_author: AI工具集
    need_open_comment: 1
    only_fans_can_comment: 0
Per-account keys (can be set per-account or globally as fallback):
default_publish_method
,
default_author
,
need_open_comment
,
only_fans_can_comment
,
app_id
,
app_secret
,
chrome_profile_path
Global-only keys (always shared across accounts):
default_theme
,
default_color
EXTEND.md支持管理多个微信公众号。当存在
accounts:
配置块时,每个账号可以拥有独立的凭证、Chrome配置文件和默认设置。
兼容规则
条件模式行为
accounts
配置块
单账号保持当前原有行为
accounts
仅1条配置
单账号自动选择该账号,无需提示
accounts
有2条及以上配置
多账号发布前提示用户选择
accounts
包含
default: true
配置
多账号预选默认账号,用户可切换
多账号EXTEND.md示例
md
default_theme: default
default_color: blue

accounts:
  - name: 宝玉的技术分享
    alias: baoyu
    default: true
    default_publish_method: api
    default_author: 宝玉
    need_open_comment: 1
    only_fans_can_comment: 0
    app_id: your_wechat_app_id
    app_secret: your_wechat_app_secret
  - name: AI工具集
    alias: ai-tools
    default_publish_method: browser
    default_author: AI工具集
    need_open_comment: 1
    only_fans_can_comment: 0
账号级配置项(可单独为每个账号设置,也可全局设置作为 fallback):
default_publish_method
,
default_author
,
need_open_comment
,
only_fans_can_comment
,
app_id
,
app_secret
,
chrome_profile_path
仅全局生效配置项(所有账号共享):
default_theme
,
default_color

Account Selection (Step 0.5)

账号选择(第0.5步)

Insert between Step 0 and Step 1 in the Article Posting Workflow:
if no accounts block:
    → single-account mode (current behavior)
elif accounts.length == 1:
    → auto-select the only account
elif --account <alias> CLI arg:
    → select matching account
elif one account has default: true:
    → pre-select, show: "Using account: <name> (--account to switch)"
else:
    → prompt user:
      "Multiple WeChat accounts configured:
       1) <name1> (<alias1>)
       2) <name2> (<alias2>)
       Select account [1-N]:"
插入到文章发布工作流的第0步和第1步之间:
if 无accounts配置块:
    → 单账号模式(原有行为)
elif accounts.length == 1:
    → 自动选择唯一的账号
elif 传入--account <alias> CLI参数:
    → 选择匹配的账号
elif 存在账号配置default: true:
    → 预选该账号,提示:"正在使用账号: <name> (可使用--account参数切换)"
else:
    → 提示用户:
      "已配置多个微信公众号账号:
       1) <name1> (<alias1>)
       2) <name2> (<alias2>)
       请选择账号 [1-N]:"

Credential Resolution (API Method)

凭证解析(API发布方式)

For a selected account with alias
{alias}
:
  1. app_id
    /
    app_secret
    inline in EXTEND.md account block
  2. Env var
    WECHAT_{ALIAS}_APP_ID
    /
    WECHAT_{ALIAS}_APP_SECRET
    (alias uppercased, hyphens → underscores)
  3. .baoyu-skills/.env
    with prefixed key
    WECHAT_{ALIAS}_APP_ID
  4. ~/.baoyu-skills/.env
    with prefixed key
  5. Fallback to unprefixed
    WECHAT_APP_ID
    /
    WECHAT_APP_SECRET
.env multi-account example:
bash
undefined
针对别名为
{alias}
的选中账号:
  1. EXTEND.md账号配置块内的
    app_id
    /
    app_secret
  2. 环境变量
    WECHAT_{ALIAS}_APP_ID
    /
    WECHAT_{ALIAS}_APP_SECRET
    (别名转为大写,连字符替换为下划线)
  3. .baoyu-skills/.env
    中前缀为
    WECHAT_{ALIAS}_APP_ID
    的配置项
  4. ~/.baoyu-skills/.env
    中前缀为
    WECHAT_{ALIAS}_APP_ID
    的配置项
  5. fallback为无前缀的
    WECHAT_APP_ID
    /
    WECHAT_APP_SECRET
.env多账号配置示例
bash
undefined

Account: baoyu

账号: baoyu

WECHAT_BAOYU_APP_ID=your_wechat_app_id WECHAT_BAOYU_APP_SECRET=your_wechat_app_secret
WECHAT_BAOYU_APP_ID=your_wechat_app_id WECHAT_BAOYU_APP_SECRET=your_wechat_app_secret

Account: ai-tools

账号: ai-tools

WECHAT_AI_TOOLS_APP_ID=your_ai_tools_wechat_app_id WECHAT_AI_TOOLS_APP_SECRET=your_ai_tools_wechat_app_secret
undefined
WECHAT_AI_TOOLS_APP_ID=your_ai_tools_wechat_app_id WECHAT_AI_TOOLS_APP_SECRET=your_ai_tools_wechat_app_secret
undefined

Chrome Profile (Browser Method)

Chrome配置文件(浏览器发布方式)

Each account uses an isolated Chrome profile for independent login sessions:
SourcePath
Account
chrome_profile_path
in EXTEND.md
Use as-is
Auto-generated from alias
{shared_profile_parent}/wechat-{alias}/
Single-account fallbackShared default profile (current behavior)
每个账号使用独立的Chrome配置文件实现登录会话隔离:
来源路径
EXTEND.md中账号的
chrome_profile_path
配置
直接使用该路径
基于别名自动生成
{shared_profile_parent}/wechat-{alias}/
单账号模式 fallback共享默认配置文件(原有行为)

CLI
--account
Argument

CLI
--account
参数

All publishing scripts accept
--account <alias>
:
bash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme default --account ai-tools
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <file> --theme default --account baoyu
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown <file> --images ./photos/ --account baoyu
所有发布脚本都支持
--account <alias>
参数:
bash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme default --account ai-tools
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <file> --theme default --account baoyu
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown <file> --images ./photos/ --account baoyu

Pre-flight Check (Optional)

前置检查(可选)

Before first use, suggest running the environment check. User can skip if they prefer.
bash
${BUN_X} {baseDir}/scripts/check-permissions.ts
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
If any check fails, provide fix guidance per item:
CheckFix
ChromeInstall Chrome or set
WECHAT_BROWSER_CHROME_PATH
env var
Profile dirShared profile at
baoyu-skills/chrome-profile
(see CLAUDE.md Chrome Profile section)
Bun runtime
brew install oven-sh/bun/bun
(macOS) or
npm install -g bun
Accessibility (macOS)System Settings → Privacy & Security → Accessibility → enable terminal app
Clipboard copyEnsure Swift/AppKit available (macOS Xcode CLI tools:
xcode-select --install
)
Paste keystroke (macOS)Same as Accessibility fix above
Paste keystroke (Linux)Install
xdotool
(X11) or
ydotool
(Wayland)
API credentialsFollow guided setup in Step 2, or manually set in
.baoyu-skills/.env
首次使用前,建议运行环境检查。用户可按需跳过。
bash
${BUN_X} {baseDir}/scripts/check-permissions.ts
检查项:Chrome、配置文件隔离、Bun、无障碍权限、剪贴板、粘贴快捷键、API凭证、Chrome冲突。
如果任意检查失败,逐项目提供修复指引:
检查项修复方案
Chrome安装Chrome或设置
WECHAT_BROWSER_CHROME_PATH
环境变量
配置文件目录使用
baoyu-skills/chrome-profile
下的共享配置(参考CLAUDE.md的Chrome配置章节)
Bun运行时macOS执行
brew install oven-sh/bun/bun
,其他系统执行
npm install -g bun
无障碍权限(macOS)系统设置 → 隐私与安全性 → 无障碍 → 开启对应终端应用的权限
剪贴板复制确保Swift/AppKit可用(macOS安装Xcode命令行工具:
xcode-select --install
粘贴快捷键(macOS)与上述无障碍权限修复方案一致
粘贴快捷键(Linux)安装
xdotool
(X11环境)或
ydotool
(Wayland环境)
API凭证按照第2步的引导设置,或手动写入
.baoyu-skills/.env

Image-Text Posting (图文)

图文发布

For short posts with multiple images (up to 9):
bash
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/
${BUN_X} {baseDir}/scripts/wechat-browser.ts --title "标题" --content "内容" --image img.png --submit
See references/image-text-posting.md for details.
适用于包含多张图片(最多9张)的短内容发布:
bash
${BUN_X} {baseDir}/scripts/wechat-browser.ts --markdown article.md --images ./images/
${BUN_X} {baseDir}/scripts/wechat-browser.ts --title "标题" --content "内容" --image img.png --submit
详情参考references/image-text-posting.md

Article Posting Workflow (文章)

文章发布工作流

Copy this checklist and check off items as you complete them:
Publishing Progress:
- [ ] Step 0: Load preferences (EXTEND.md)
- [ ] Step 0.5: Resolve account (multi-account only)
- [ ] Step 1: Determine input type
- [ ] Step 2: Select method and configure credentials
- [ ] Step 3: Resolve theme/color and validate metadata
- [ ] Step 4: Publish to WeChat
- [ ] Step 5: Report completion
复制以下 checklist,完成对应步骤后勾选:
发布进度:
- [ ] 第0步:加载偏好配置(EXTEND.md)
- [ ] 第0.5步:解析账号(仅多账号模式)
- [ ] 第1步:确定输入类型
- [ ] 第2步:选择发布方式并配置凭证
- [ ] 第3步:解析主题/颜色并验证元数据
- [ ] 第4步:发布到微信公众号
- [ ] 第5步:报告完成结果

Step 0: Load Preferences

第0步:加载偏好配置

Check and load EXTEND.md settings (see Preferences section above).
CRITICAL: If not found, complete first-time setup BEFORE any other steps or questions.
Resolve and store these defaults for later steps:
  • default_theme
    (default
    default
    )
  • default_color
    (omit if not set — theme default applies)
  • default_author
  • need_open_comment
    (default
    1
    )
  • only_fans_can_comment
    (default
    0
    )
检查并加载EXTEND.md设置(参考上文偏好配置章节)。
重要提示:如果未找到配置文件,必须先完成首次设置,再执行其他步骤或响应用户问题。
解析并存储以下默认配置供后续步骤使用:
  • default_theme
    (默认
    default
  • default_color
    (未设置则省略,使用主题默认颜色)
  • default_author
  • need_open_comment
    (默认
    1
  • only_fans_can_comment
    (默认
    0

Step 1: Determine Input Type

第1步:确定输入类型

Input TypeDetectionAction
HTML filePath ends with
.html
, file exists
Skip to Step 3
Markdown filePath ends with
.md
, file exists
Continue to Step 2
Plain textNot a file path, or file doesn't existSave to markdown, continue to Step 2
Plain Text Handling:
  1. Generate slug from content (first 2-4 meaningful words, kebab-case)
  2. Create directory and save file:
bash
mkdir -p "$(pwd)/post-to-wechat/$(date +%Y-%m-%d)"
输入类型检测规则操作
HTML文件路径以
.html
结尾且文件存在
直接跳转到第3步
Markdown文件路径以
.md
结尾且文件存在
继续执行第2步
纯文本不是文件路径或文件不存在保存为Markdown文件,继续执行第2步
纯文本处理逻辑
  1. 从内容生成slug(提取前2-4个有意义的词,转为kebab-case格式)
  2. 创建目录并保存文件:
bash
mkdir -p "$(pwd)/post-to-wechat/$(date +%Y-%m-%d)"

Save content to: post-to-wechat/yyyy-MM-dd/[slug].md

保存内容到: post-to-wechat/yyyy-MM-dd/[slug].md


3. Continue processing as markdown file

**Slug Examples**:
- "Understanding AI Models" → `understanding-ai-models`
- "人工智能的未来" → `ai-future` (translate to English for slug)

3. 作为Markdown文件继续处理

**Slug示例**:
- "Understanding AI Models" → `understanding-ai-models`
- "人工智能的未来" → `ai-future`(中文内容翻译为英文生成slug)

Step 2: Select Publishing Method and Configure

第2步:选择发布方式并配置

Ask publishing method (unless specified in EXTEND.md or CLI):
MethodSpeedRequirements
api
(Recommended)
FastAPI credentials
browser
SlowChrome, login session
If API Selected - Check Credentials:
bash
undefined
询问用户发布方式(除非EXTEND.md或CLI参数已指定):
发布方式速度要求
api
(推荐)
需要API凭证
browser
需要Chrome和登录会话
如果选择API方式 - 检查凭证
bash
undefined

macOS, Linux, WSL, Git Bash

macOS, Linux, WSL, Git Bash

test -f .baoyu-skills/.env && grep -q "WECHAT_APP_ID" .baoyu-skills/.env && echo "project" test -f "$HOME/.baoyu-skills/.env" && grep -q "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env" && echo "user"

```powershell
test -f .baoyu-skills/.env && grep -q "WECHAT_APP_ID" .baoyu-skills/.env && echo "project" test -f "$HOME/.baoyu-skills/.env" && grep -q "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env" && echo "user"

```powershell

PowerShell (Windows)

PowerShell (Windows)

if ((Test-Path .baoyu-skills/.env) -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" .baoyu-skills/.env)) { "project" } if ((Test-Path "$HOME/.baoyu-skills/.env") -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env")) { "user" }

**If Credentials Missing - Guide Setup**:
WeChat API credentials not found.
To obtain credentials:
  1. Visit https://mp.weixin.qq.com
  2. Go to: 开发 → 基本配置
  3. Copy AppID and AppSecret
Where to save? A) Project-level: .baoyu-skills/.env (this project only) B) User-level: ~/.baoyu-skills/.env (all projects)

After location choice, prompt for values and write to `.env`:
WECHAT_APP_ID=<user_input> WECHAT_APP_SECRET=<user_input>
undefined
if ((Test-Path .baoyu-skills/.env) -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" .baoyu-skills/.env)) { "project" } if ((Test-Path "$HOME/.baoyu-skills/.env") -and (Select-String -Quiet -Pattern "WECHAT_APP_ID" "$HOME/.baoyu-skills/.env")) { "user" }

**如果凭证缺失 - 引导设置**:
未找到微信API凭证。
获取凭证步骤:
  1. 访问 https://mp.weixin.qq.com
  2. 进入:开发 → 基本配置
  3. 复制AppID和AppSecret
保存位置选择: A) 项目级别:.baoyu-skills/.env(仅当前项目生效) B) 用户级别:~/.baoyu-skills/.env(所有项目生效)

用户选择保存位置后,提示输入对应值并写入`.env`:
WECHAT_APP_ID=<用户输入值> WECHAT_APP_SECRET=<用户输入值>
undefined

Step 3: Resolve Theme/Color and Validate Metadata

第3步:解析主题/颜色并验证元数据

  1. Resolve theme (first match wins, do NOT ask user if resolved):
    • CLI
      --theme
      argument
    • EXTEND.md
      default_theme
      (loaded in Step 0)
    • Fallback:
      default
  2. Resolve color (first match wins):
    • CLI
      --color
      argument
    • EXTEND.md
      default_color
      (loaded in Step 0)
    • Omit if not set (theme default applies)
  3. Validate metadata from frontmatter (markdown) or HTML meta tags (HTML input):
FieldIf Missing
TitlePrompt: "Enter title, or press Enter to auto-generate from content"
SummaryPrompt: "Enter summary, or press Enter to auto-generate (recommended for SEO)"
AuthorUse fallback chain: CLI
--author
→ frontmatter
author
→ EXTEND.md
default_author
Auto-Generation Logic:
  • Title: First H1/H2 heading, or first sentence
  • Summary: First paragraph, truncated to 120 characters
  1. Cover Image Check (required for API
    article_type=news
    ):
    1. Use CLI
      --cover
      if provided.
    2. Else use frontmatter (
      coverImage
      ,
      featureImage
      ,
      cover
      ,
      image
      ).
    3. Else check article directory default path:
      imgs/cover.png
      .
    4. Else fallback to first inline content image.
    5. If still missing, stop and request a cover image before publishing.
  1. 解析主题(首个匹配项生效,解析成功无需询问用户):
    • CLI
      --theme
      参数
    • EXTEND.md的
      default_theme
      配置(第0步加载)
    • Fallback:
      default
  2. 解析颜色(首个匹配项生效):
    • CLI
      --color
      参数
    • EXTEND.md的
      default_color
      配置(第0步加载)
    • 未设置则省略(使用主题默认颜色)
  3. 验证元数据:从Markdown文章头或HTML meta标签中提取:
字段缺失处理
标题提示:"输入标题,或按回车自动从内容生成"
摘要提示:"输入摘要,或按回车自动生成(利于SEO)"
作者优先级 fallback:CLI
--author
→ 文章头
author
→ EXTEND.md
default_author
自动生成逻辑
  • 标题:首个H1/H2标题,或首句内容
  • 摘要:首段内容,截断为120字符
  1. 封面图片检查(API发布
    article_type=news
    时必填):
    1. 如果提供CLI
      --cover
      参数则使用
    2. 否则使用文章头配置(
      coverImage
      featureImage
      cover
      image
    3. 否则检查文章目录默认路径:
      imgs/cover.png
    4. 否则 fallback为内容中第一张内联图片
    5. 仍缺失则终止流程,要求用户提供封面图片后再发布

Step 4: Publish to WeChat

第4步:发布到微信公众号

CRITICAL: Publishing scripts handle markdown conversion internally. Do NOT pre-convert markdown to HTML — pass the original markdown file directly. This ensures the API method renders images as
<img>
tags (for API upload) while the browser method uses placeholders (for paste-and-replace workflow).
Markdown citation default:
  • For markdown input, ordinary external links are converted to bottom citations by default.
  • Use
    --no-cite
    only if the user explicitly wants to keep ordinary external links inline.
  • Existing HTML input is left as-is; no extra citation conversion is applied.
API method (accepts
.md
or
.html
):
bash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]
CRITICAL: Always include
--theme
parameter. Never omit it, even if using
default
. Only include
--color
if explicitly set by user or EXTEND.md.
draft/add
payload rules
:
  • Use endpoint:
    POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN
  • article_type
    :
    news
    (default) or
    newspic
  • For
    news
    , include
    thumb_media_id
    (cover is required)
  • Always resolve and send:
    • need_open_comment
      (default
      1
      )
    • only_fans_can_comment
      (default
      0
      )
  • author
    resolution: CLI
    --author
    → frontmatter
    author
    → EXTEND.md
    default_author
If script parameters do not expose the two comment fields, still ensure final API request body includes resolved values.
Browser method (accepts
--markdown
or
--html
):
bash
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite]
${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file>
重要提示:发布脚本内置Markdown转换逻辑,不要提前将Markdown转换为HTML,直接传入原始Markdown文件即可。这样可以保证API方式将图片渲染为
<img>
标签(用于API上传),而浏览器方式使用占位符(用于粘贴替换工作流)。
Markdown引用默认规则
  • Markdown输入默认将普通外部链接转换为底部引用
  • 仅当用户明确要求保留行内外部链接时,使用
    --no-cite
    参数
  • 已有的HTML输入保持原样,不额外进行引用转换
API方式(支持
.md
.html
输入):
bash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]
重要提示:始终传入
--theme
参数,即使使用
default
主题也不可省略。仅当用户或EXTEND.md明确设置了颜色时,才传入
--color
参数。
draft/add
请求体规则
  • 请求接口:
    POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN
  • article_type
    news
    (默认)或
    newspic
  • news
    类型需要传入
    thumb_media_id
    (封面必填)
  • 始终解析并传入:
    • need_open_comment
      (默认
      1
    • only_fans_can_comment
      (默认
      0
  • author
    解析优先级:CLI
    --author
    → 文章头
    author
    → EXTEND.md
    default_author
如果脚本参数未暴露两个评论字段,也要确保最终API请求体中包含解析后的对应值。
浏览器方式(支持
--markdown
--html
输入):
bash
${BUN_X} {baseDir}/scripts/wechat-article.ts --markdown <markdown_file> --theme <theme> [--color <color>] [--no-cite]
${BUN_X} {baseDir}/scripts/wechat-article.ts --html <html_file>

Step 5: Completion Report

第5步:完成结果报告

For API method, include draft management link:
WeChat Publishing Complete!

Input: [type] - [path]
Method: API
Theme: [theme name] [color if set]

Article:
• Title: [title]
• Summary: [summary]
• Images: [N] inline images
• Comments: [open/closed], [fans-only/all users]

Result:
✓ Draft saved to WeChat Official Account
• media_id: [media_id]

Next Steps:
→ Manage drafts: https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)

Files created:
[• post-to-wechat/yyyy-MM-dd/slug.md (if plain text)]
[• slug.html (converted)]
For Browser method:
WeChat Publishing Complete!

Input: [type] - [path]
Method: Browser
Theme: [theme name] [color if set]

Article:
• Title: [title]
• Summary: [summary]
• Images: [N] inline images

Result:
✓ Draft saved to WeChat Official Account

Files created:
[• post-to-wechat/yyyy-MM-dd/slug.md (if plain text)]
[• slug.html (converted)]
API方式返回结果需包含草稿管理链接:
微信公众号发布完成!

输入: [类型] - [路径]
方式: API
主题: [主题名称] [已设置的颜色]

文章信息:
• 标题: [标题]
• 摘要: [摘要]
• 图片: [N]张内联图片
• 评论: [开启/关闭], [仅粉丝/所有用户可评论]

发布结果:
✓ 草稿已保存到微信公众号
• media_id: [media_id]

后续步骤:
→ 管理草稿:https://mp.weixin.qq.com (登录后进入「内容管理」→「草稿箱」)

生成的文件:
[• post-to-wechat/yyyy-MM-dd/slug.md (如果是纯文本输入)]
[• slug.html (转换后的文件)]
浏览器方式返回结果:
微信公众号发布完成!

输入: [类型] - [路径]
方式: Browser
主题: [主题名称] [已设置的颜色]

文章信息:
• 标题: [标题]
• 摘要: [摘要]
• 图片: [N]张内联图片

发布结果:
✓ 草稿已保存到微信公众号

生成的文件:
[• post-to-wechat/yyyy-MM-dd/slug.md (如果是纯文本输入)]
[• slug.html (转换后的文件)]

Detailed References

详细参考文档

TopicReference
Image-text parameters, auto-compressionreferences/image-text-posting.md
Article themes, image handlingreferences/article-posting.md
主题参考链接
图文发布参数、自动压缩references/image-text-posting.md
文章主题、图片处理references/article-posting.md

Feature Comparison

功能对比

FeatureImage-TextArticle (API)Article (Browser)
Plain text input
HTML input
Markdown inputTitle/content
Multiple images✓ (up to 9)✓ (inline)✓ (inline)
Themes
Auto-generate metadata
Default cover fallback (
imgs/cover.png
)
Comment control (
need_open_comment
,
only_fans_can_comment
)
Requires Chrome
Requires API credentials
SpeedMediumFastSlow
功能图文文章(API)文章(浏览器)
纯文本输入
HTML输入
Markdown输入仅标题/内容
多图支持✓(最多9张)✓(内联)✓(内联)
主题支持
自动生成元数据
默认封面 fallback(
imgs/cover.png
评论控制(
need_open_comment
only_fans_can_comment
需要Chrome
需要API凭证
速度中等

Prerequisites

前置要求

For API method:
  • WeChat Official Account API credentials
  • Guided setup in Step 2, or manually set in
    .baoyu-skills/.env
For Browser method:
  • Google Chrome
  • First run: log in to WeChat Official Account (session preserved)
Config File Locations (priority order):
  1. Environment variables
  2. <cwd>/.baoyu-skills/.env
  3. ~/.baoyu-skills/.env
API发布方式
  • 微信公众号API凭证
  • 按第2步引导设置,或手动写入
    .baoyu-skills/.env
浏览器发布方式
  • Google Chrome
  • 首次运行:登录微信公众号(会话会自动保存)
配置文件位置优先级
  1. 环境变量
  2. <当前工作目录>/.baoyu-skills/.env
  3. ~/.baoyu-skills/.env

Troubleshooting

故障排查

IssueSolution
Missing API credentialsFollow guided setup in Step 2
Access token errorCheck if API credentials are valid and not expired
Not logged in (browser)First run opens browser - scan QR to log in
Chrome not foundSet
WECHAT_BROWSER_CHROME_PATH
env var
Title/summary missingUse auto-generation or provide manually
No cover imageAdd frontmatter cover or place
imgs/cover.png
in article directory
Wrong comment defaultsCheck
EXTEND.md
keys
need_open_comment
and
only_fans_can_comment
Paste failsCheck system clipboard permissions
问题解决方案
缺失API凭证按照第2步引导设置
Access token错误检查API凭证是否有效、是否过期
未登录(浏览器方式)首次运行会打开浏览器,扫码登录即可
未找到Chrome设置
WECHAT_BROWSER_CHROME_PATH
环境变量
标题/摘要缺失使用自动生成功能或手动提供
无封面图片在文章头添加封面配置,或在文章目录放置
imgs/cover.png
评论默认值错误检查EXTEND.md中的
need_open_comment
only_fans_can_comment
配置
粘贴失败检查系统剪贴板权限

Extension Support

扩展支持

Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
通过EXTEND.md进行自定义配置,路径和支持选项参考偏好配置章节。