baoyu-post-to-wechat
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePost 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 , then use . Resolve runtime: if installed → ; if available → ; else suggest installing bun.
{baseDir}{baseDir}/scripts/<name>.ts${BUN_X}bunbunnpxnpx -y bun| Script | Purpose |
|---|---|
| Image-text posts (图文) |
| Article posting via browser (文章) |
| Article posting via API (文章) |
| Markdown → WeChat-ready HTML with image placeholders |
| Verify environment & permissions |
Agent执行:将此SKILL.md所在目录判定为,随后使用。解析运行时:如果已安装则使用;如果可用则使用;否则建议用户安装bun。
{baseDir}{baseDir}/scripts/<name>.ts${BUN_X}bunbunnpxnpx -y bun| 脚本 | 用途 |
|---|---|
| 图文发布 |
| 通过浏览器发布文章 |
| 通过API发布文章 |
| 将Markdown转换为带图片占位符的微信兼容HTML |
| 验证环境与权限 |
Preferences (EXTEND.md)
偏好配置(EXTEND.md)
Check EXTEND.md existence (priority order):
bash
undefined按优先级顺序检查EXTEND.md是否存在:
bash
undefinedmacOS, 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"
```powershelltest -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"
```powershellPowerShell (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/profileTheme 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:
- CLI arguments
- Frontmatter
- EXTEND.md (account-level → global-level)
- 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(也可使用十六进制色值)
配置值优先级:
- CLI参数
- 文章头配置
- EXTEND.md(账号级别 → 全局级别)
- 工具默认值
Multi-Account Support
多账号支持
EXTEND.md supports managing multiple WeChat Official Accounts. When block is present, each account can have its own credentials, Chrome profile, and default settings.
accounts:Compatibility rules:
| Condition | Mode | Behavior |
|---|---|---|
No | Single-account | Current behavior, unchanged |
| Single-account | Auto-select, no prompt |
| Multi-account | Prompt to select before publishing |
| Multi-account | Pre-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: 0Per-account keys (can be set per-account or globally as fallback):
, , , , , ,
default_publish_methoddefault_authorneed_open_commentonly_fans_can_commentapp_idapp_secretchrome_profile_pathGlobal-only keys (always shared across accounts):
,
default_themedefault_colorEXTEND.md支持管理多个微信公众号。当存在配置块时,每个账号可以拥有独立的凭证、Chrome配置文件和默认设置。
accounts:兼容规则:
| 条件 | 模式 | 行为 |
|---|---|---|
无 | 单账号 | 保持当前原有行为 |
| 单账号 | 自动选择该账号,无需提示 |
| 多账号 | 发布前提示用户选择 |
| 多账号 | 预选默认账号,用户可切换 |
多账号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_methoddefault_authorneed_open_commentonly_fans_can_commentapp_idapp_secretchrome_profile_path仅全局生效配置项(所有账号共享):
,
default_themedefault_colorAccount 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}- /
app_idinline in EXTEND.md account blockapp_secret - Env var /
WECHAT_{ALIAS}_APP_ID(alias uppercased, hyphens → underscores)WECHAT_{ALIAS}_APP_SECRET - with prefixed key
.baoyu-skills/.envWECHAT_{ALIAS}_APP_ID - with prefixed key
~/.baoyu-skills/.env - Fallback to unprefixed /
WECHAT_APP_IDWECHAT_APP_SECRET
.env multi-account example:
bash
undefined针对别名为的选中账号:
{alias}- EXTEND.md账号配置块内的/
app_idapp_secret - 环境变量/
WECHAT_{ALIAS}_APP_ID(别名转为大写,连字符替换为下划线)WECHAT_{ALIAS}_APP_SECRET - 中前缀为
.baoyu-skills/.env的配置项WECHAT_{ALIAS}_APP_ID - 中前缀为
~/.baoyu-skills/.env的配置项WECHAT_{ALIAS}_APP_ID - fallback为无前缀的/
WECHAT_APP_IDWECHAT_APP_SECRET
.env多账号配置示例:
bash
undefinedAccount: 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
undefinedWECHAT_AI_TOOLS_APP_ID=your_ai_tools_wechat_app_id
WECHAT_AI_TOOLS_APP_SECRET=your_ai_tools_wechat_app_secret
undefinedChrome Profile (Browser Method)
Chrome配置文件(浏览器发布方式)
Each account uses an isolated Chrome profile for independent login sessions:
| Source | Path |
|---|---|
Account | Use as-is |
| Auto-generated from alias | |
| Single-account fallback | Shared default profile (current behavior) |
每个账号使用独立的Chrome配置文件实现登录会话隔离:
| 来源 | 路径 |
|---|---|
EXTEND.md中账号的 | 直接使用该路径 |
| 基于别名自动生成 | |
| 单账号模式 fallback | 共享默认配置文件(原有行为) |
CLI --account
Argument
--accountCLI --account
参数
--accountAll 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 baoyuPre-flight Check (Optional)
前置检查(可选)
Before first use, suggest running the environment check. User can skip if they prefer.
bash
${BUN_X} {baseDir}/scripts/check-permissions.tsChecks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
If any check fails, provide fix guidance per item:
| Check | Fix |
|---|---|
| Chrome | Install Chrome or set |
| Profile dir | Shared profile at |
| Bun runtime | |
| Accessibility (macOS) | System Settings → Privacy & Security → Accessibility → enable terminal app |
| Clipboard copy | Ensure Swift/AppKit available (macOS Xcode CLI tools: |
| Paste keystroke (macOS) | Same as Accessibility fix above |
| Paste keystroke (Linux) | Install |
| API credentials | Follow guided setup in Step 2, or manually set in |
首次使用前,建议运行环境检查。用户可按需跳过。
bash
${BUN_X} {baseDir}/scripts/check-permissions.ts检查项:Chrome、配置文件隔离、Bun、无障碍权限、剪贴板、粘贴快捷键、API凭证、Chrome冲突。
如果任意检查失败,逐项目提供修复指引:
| 检查项 | 修复方案 |
|---|---|
| Chrome | 安装Chrome或设置 |
| 配置文件目录 | 使用 |
| Bun运行时 | macOS执行 |
| 无障碍权限(macOS) | 系统设置 → 隐私与安全性 → 无障碍 → 开启对应终端应用的权限 |
| 剪贴板复制 | 确保Swift/AppKit可用(macOS安装Xcode命令行工具: |
| 粘贴快捷键(macOS) | 与上述无障碍权限修复方案一致 |
| 粘贴快捷键(Linux) | 安装 |
| API凭证 | 按照第2步的引导设置,或手动写入 |
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 --submitSee 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
default_theme)default - (omit if not set — theme default applies)
default_color default_author- (default
need_open_comment)1 - (default
only_fans_can_comment)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 Type | Detection | Action |
|---|---|---|
| HTML file | Path ends with | Skip to Step 3 |
| Markdown file | Path ends with | Continue to Step 2 |
| Plain text | Not a file path, or file doesn't exist | Save to markdown, continue to Step 2 |
Plain Text Handling:
- Generate slug from content (first 2-4 meaningful words, kebab-case)
- Create directory and save file:
bash
mkdir -p "$(pwd)/post-to-wechat/$(date +%Y-%m-%d)"| 输入类型 | 检测规则 | 操作 |
|---|---|---|
| HTML文件 | 路径以 | 直接跳转到第3步 |
| Markdown文件 | 路径以 | 继续执行第2步 |
| 纯文本 | 不是文件路径或文件不存在 | 保存为Markdown文件,继续执行第2步 |
纯文本处理逻辑:
- 从内容生成slug(提取前2-4个有意义的词,转为kebab-case格式)
- 创建目录并保存文件:
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):
| Method | Speed | Requirements |
|---|---|---|
| Fast | API credentials |
| Slow | Chrome, login session |
If API Selected - Check Credentials:
bash
undefined询问用户发布方式(除非EXTEND.md或CLI参数已指定):
| 发布方式 | 速度 | 要求 |
|---|---|---|
| 快 | 需要API凭证 |
| 慢 | 需要Chrome和登录会话 |
如果选择API方式 - 检查凭证:
bash
undefinedmacOS, 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"
```powershelltest -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"
```powershellPowerShell (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:
- Visit https://mp.weixin.qq.com
- Go to: 开发 → 基本配置
- 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>
undefinedif ((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凭证。
获取凭证步骤:
- 访问 https://mp.weixin.qq.com
- 进入:开发 → 基本配置
- 复制AppID和AppSecret
保存位置选择:
A) 项目级别:.baoyu-skills/.env(仅当前项目生效)
B) 用户级别:~/.baoyu-skills/.env(所有项目生效)
用户选择保存位置后,提示输入对应值并写入`.env`:
WECHAT_APP_ID=<用户输入值>
WECHAT_APP_SECRET=<用户输入值>
undefinedStep 3: Resolve Theme/Color and Validate Metadata
第3步:解析主题/颜色并验证元数据
-
Resolve theme (first match wins, do NOT ask user if resolved):
- CLI argument
--theme - EXTEND.md (loaded in Step 0)
default_theme - Fallback:
default
- CLI
-
Resolve color (first match wins):
- CLI argument
--color - EXTEND.md (loaded in Step 0)
default_color - Omit if not set (theme default applies)
- CLI
-
Validate metadata from frontmatter (markdown) or HTML meta tags (HTML input):
| Field | If Missing |
|---|---|
| Title | Prompt: "Enter title, or press Enter to auto-generate from content" |
| Summary | Prompt: "Enter summary, or press Enter to auto-generate (recommended for SEO)" |
| Author | Use fallback chain: CLI |
Auto-Generation Logic:
- Title: First H1/H2 heading, or first sentence
- Summary: First paragraph, truncated to 120 characters
- Cover Image Check (required for API ):
article_type=news- Use CLI if provided.
--cover - Else use frontmatter (,
coverImage,featureImage,cover).image - Else check article directory default path: .
imgs/cover.png - Else fallback to first inline content image.
- If still missing, stop and request a cover image before publishing.
- Use CLI
-
解析主题(首个匹配项生效,解析成功无需询问用户):
- CLI 参数
--theme - EXTEND.md的配置(第0步加载)
default_theme - Fallback:
default
- CLI
-
解析颜色(首个匹配项生效):
- CLI 参数
--color - EXTEND.md的配置(第0步加载)
default_color - 未设置则省略(使用主题默认颜色)
- CLI
-
验证元数据:从Markdown文章头或HTML meta标签中提取:
| 字段 | 缺失处理 |
|---|---|
| 标题 | 提示:"输入标题,或按回车自动从内容生成" |
| 摘要 | 提示:"输入摘要,或按回车自动生成(利于SEO)" |
| 作者 | 优先级 fallback:CLI |
自动生成逻辑:
- 标题:首个H1/H2标题,或首句内容
- 摘要:首段内容,截断为120字符
- 封面图片检查(API发布时必填):
article_type=news- 如果提供CLI 参数则使用
--cover - 否则使用文章头配置(、
coverImage、featureImage、cover)image - 否则检查文章目录默认路径:
imgs/cover.png - 否则 fallback为内容中第一张内联图片
- 仍缺失则终止流程,要求用户提供封面图片后再发布
- 如果提供CLI
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 tags (for API upload) while the browser method uses placeholders (for paste-and-replace workflow).
<img>Markdown citation default:
- For markdown input, ordinary external links are converted to bottom citations by default.
- Use only if the user explicitly wants to keep ordinary external links inline.
--no-cite - Existing HTML input is left as-is; no extra citation conversion is applied.
API method (accepts or ):
.md.htmlbash
${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 parameter. Never omit it, even if using . Only include if explicitly set by user or EXTEND.md.
--themedefault--colordraft/add- Use endpoint:
POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN - :
article_type(default) ornewsnewspic - For , include
news(cover is required)thumb_media_id - Always resolve and send:
- (default
need_open_comment)1 - (default
only_fans_can_comment)0
- resolution: CLI
author→ frontmatter--author→ EXTEND.mdauthordefault_author
If script parameters do not expose the two comment fields, still ensure final API request body includes resolved values.
Browser method (accepts or ):
--markdown--htmlbash
${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方式将图片渲染为标签(用于API上传),而浏览器方式使用占位符(用于粘贴替换工作流)。
<img>Markdown引用默认规则:
- Markdown输入默认将普通外部链接转换为底部引用
- 仅当用户明确要求保留行内外部链接时,使用参数
--no-cite - 已有的HTML输入保持原样,不额外进行引用转换
API方式(支持或输入):
.md.htmlbash
${BUN_X} {baseDir}/scripts/wechat-api.ts <file> --theme <theme> [--color <color>] [--title <title>] [--summary <summary>] [--author <author>] [--cover <cover_path>] [--no-cite]重要提示:始终传入参数,即使使用主题也不可省略。仅当用户或EXTEND.md明确设置了颜色时,才传入参数。
--themedefault--colordraft/add- 请求接口:
POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN - :
article_type(默认)或newsnewspic - 类型需要传入
news(封面必填)thumb_media_id - 始终解析并传入:
- (默认
need_open_comment)1 - (默认
only_fans_can_comment)0
- 解析优先级:CLI
author→ 文章头--author→ EXTEND.mdauthordefault_author
如果脚本参数未暴露两个评论字段,也要确保最终API请求体中包含解析后的对应值。
浏览器方式(支持或输入):
--markdown--htmlbash
${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
详细参考文档
| Topic | Reference |
|---|---|
| Image-text parameters, auto-compression | references/image-text-posting.md |
| Article themes, image handling | references/article-posting.md |
| 主题 | 参考链接 |
|---|---|
| 图文发布参数、自动压缩 | references/image-text-posting.md |
| 文章主题、图片处理 | references/article-posting.md |
Feature Comparison
功能对比
| Feature | Image-Text | Article (API) | Article (Browser) |
|---|---|---|---|
| Plain text input | ✗ | ✓ | ✓ |
| HTML input | ✗ | ✓ | ✓ |
| Markdown input | Title/content | ✓ | ✓ |
| Multiple images | ✓ (up to 9) | ✓ (inline) | ✓ (inline) |
| Themes | ✗ | ✓ | ✓ |
| Auto-generate metadata | ✗ | ✓ | ✓ |
Default cover fallback ( | ✗ | ✓ | ✗ |
Comment control ( | ✗ | ✓ | ✗ |
| Requires Chrome | ✓ | ✗ | ✓ |
| Requires API credentials | ✗ | ✓ | ✗ |
| Speed | Medium | Fast | Slow |
| 功能 | 图文 | 文章(API) | 文章(浏览器) |
|---|---|---|---|
| 纯文本输入 | ✗ | ✓ | ✓ |
| HTML输入 | ✗ | ✓ | ✓ |
| Markdown输入 | 仅标题/内容 | ✓ | ✓ |
| 多图支持 | ✓(最多9张) | ✓(内联) | ✓(内联) |
| 主题支持 | ✗ | ✓ | ✓ |
| 自动生成元数据 | ✗ | ✓ | ✓ |
默认封面 fallback( | ✗ | ✓ | ✗ |
评论控制( | ✗ | ✓ | ✗ |
| 需要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):
- Environment variables
<cwd>/.baoyu-skills/.env~/.baoyu-skills/.env
API发布方式:
- 微信公众号API凭证
- 按第2步引导设置,或手动写入
.baoyu-skills/.env
浏览器发布方式:
- Google Chrome
- 首次运行:登录微信公众号(会话会自动保存)
配置文件位置优先级:
- 环境变量
<当前工作目录>/.baoyu-skills/.env~/.baoyu-skills/.env
Troubleshooting
故障排查
| Issue | Solution |
|---|---|
| Missing API credentials | Follow guided setup in Step 2 |
| Access token error | Check if API credentials are valid and not expired |
| Not logged in (browser) | First run opens browser - scan QR to log in |
| Chrome not found | Set |
| Title/summary missing | Use auto-generation or provide manually |
| No cover image | Add frontmatter cover or place |
| Wrong comment defaults | Check |
| Paste fails | Check system clipboard permissions |
| 问题 | 解决方案 |
|---|---|
| 缺失API凭证 | 按照第2步引导设置 |
| Access token错误 | 检查API凭证是否有效、是否过期 |
| 未登录(浏览器方式) | 首次运行会打开浏览器,扫码登录即可 |
| 未找到Chrome | 设置 |
| 标题/摘要缺失 | 使用自动生成功能或手动提供 |
| 无封面图片 | 在文章头添加封面配置,或在文章目录放置 |
| 评论默认值错误 | 检查EXTEND.md中的 |
| 粘贴失败 | 检查系统剪贴板权限 |
Extension Support
扩展支持
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
通过EXTEND.md进行自定义配置,路径和支持选项参考偏好配置章节。