yy-post-to-wx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese通过微信公众号 API 直接将本地 Markdown/HTML 文章发布到公众号草稿箱。支持多主题、多颜色预设,自动上传图片。
Directly publish local Markdown/HTML articles to WeChat Official Account draft box via WeChat Official Account API. Supports multiple themes, preset colors, and automatic image upload.
功能特性
Features
- ✅ 支持 Markdown、HTML、纯文本三种输入
- ✅ 四种主题样式:default、grace、simple、modern
- ✅ 十二种颜色预设,支持自定义颜色
- ✅ 自动上传本地图片到微信素材库
- ✅ 外链默认转换为底部引用
- ✅ 配置文件支持默认作者、评论设置
- ✅ 通过 API 直传,无需浏览器自动化
- ✅ Supports three input formats: Markdown, HTML, plain text
- ✅ Four theme styles: default, grace, simple, modern
- ✅ Twelve preset colors, supports custom colors
- ✅ Automatically upload local images to WeChat material library
- ✅ External links are converted to bottom citations by default
- ✅ Configuration file supports default author and comment settings
- ✅ Direct upload via API, no browser automation required
配置
Configuration
首次配置
First-time Configuration
-
获取微信公众号 API 凭证:
- 访问 https://mp.weixin.qq.com
- 进入 开发 → 基本配置
- 复制 AppID 和 AppSecret
-
保存凭证到环境变量:
- 项目级:创建 文件
.baoyu-skills/.env - 用户级:创建 文件
~/.baoyu-skills/.env
- 项目级:创建
env
WECHAT_APP_ID=your_app_id
WECHAT_APP_SECRET=your_app_secret- 创建配置文件 (可选):
EXTEND.md
md
default_theme: default
default_color: blue
default_author: 你的名字
need_open_comment: 1
only_fans_can_comment: 0-
Obtain WeChat Official Account API credentials:
- Visit https://mp.weixin.qq.com
- Go to Development → Basic Configuration
- Copy AppID and AppSecret
-
Save credentials to environment variables:
- Project-level: Create file
.baoyu-skills/.env - User-level: Create file
~/.baoyu-skills/.env
- Project-level: Create
env
WECHAT_APP_ID=your_app_id
WECHAT_APP_SECRET=your_app_secret- Create configuration file (optional):
EXTEND.md
md
default_theme: default
default_color: blue
default_author: Your Name
need_open_comment: 1
only_fans_can_comment: 0配置项说明
Configuration Item Description
| 配置项 | 说明 | 默认值 |
|---|---|---|
| 默认主题 | |
| 默认颜色 | 主题默认 |
| 默认作者 | 空 |
| 是否开启评论 | |
| 是否仅粉丝可评论 | |
| Configuration Item | Description | Default Value |
|---|---|---|
| Default theme | |
| Default color | Theme default |
| Default author | Empty |
| Whether to enable comments | |
| Whether only fans can comment | |
主题选项
Theme Options
- - 默认主题,简洁大方
default - - 优雅风格,更大行高
grace - - 极简风格,去掉边框阴影
simple - - 现代风格,卡片式设计
modern
- - Default theme, concise and elegant
default - - Elegant style, larger line height
grace - - Minimalist style, removes borders and shadows
simple - - Modern style, card-based design
modern
颜色预设
Color Presets
bluegreenvermilionyellowpurpleskyroseoliveblackgraypinkredorange也可以使用自定义 hex 颜色值,如 。
#ff0000bluegreenvermilionyellowpurpleskyroseoliveblackgraypinkredorangeCustom hex color values are also supported, such as .
#ff0000使用方法
Usage
bash
undefinedbash
undefined使用 Bun
Using Bun
bun skills/yy-post-to-wx/scripts/main.ts <file> [options]
bun skills/yy-post-to-wx/scripts/main.ts <file> [options]
使用 npx bun
Using npx bun
npx -y bun skills/yy-post-to-wx/scripts/main.ts <file> [options]
undefinednpx -y bun skills/yy-post-to-wx/scripts/main.ts <file> [options]
undefined参数选项
Parameter Options
| 参数 | 说明 | 示例 |
|---|---|---|
| 输入文件路径 | |
| 主题名称 | |
| 颜色名称或 hex | |
| 强制指定标题 | |
| 强制指定摘要 | |
| 强制指定作者 | |
| 指定封面图片 | |
| 禁用外链转底部引用 | |
| Parameter | Description | Example |
|---|---|---|
| Input file path | |
| Theme name | |
| Color name or hex | |
| Force specify title | |
| Force specify summary | |
| Force specify author | |
| Specify cover image | |
| Disable external link to bottom citation conversion | |
示例
Examples
bash
undefinedbash
undefined发布 Markdown 文件
Publish Markdown file
bun skills/yy-post-to-wx/scripts/main.ts ./my-article.md --theme default --color blue
bun skills/yy-post-to-wx/scripts/main.ts ./my-article.md --theme default --color blue
指定作者和封面
Specify author and cover
bun skills/yy-post-to-wx/scripts/main.ts ./post.md --author "宝玉" --cover ./imgs/cover.png
bun skills/yy-post-to-wx/scripts/main.ts ./post.md --author "Baoyu" --cover ./imgs/cover.png
禁用引用转换
Disable citation conversion
bun skills/yy-post-to-wx/scripts/main.ts ./article.md --no-cite
undefinedbun skills/yy-post-to-wx/scripts/main.ts ./article.md --no-cite
undefined工作流程
Workflow
- 加载配置 - 从 EXTEND.md 和 .env 加载配置
- 处理输入 - 读取 Markdown/HTML 文件,纯文本自动保存
- 解析元数据 - 从 frontmatter 提取标题、作者、摘要、封面
- 转换格式 - Markdown 转换为微信兼容 HTML,应用主题样式
- 获取 Token - 通过 API 获取 access_token
- 上传图片 - 上传封面和正文图片,替换 URL
- 创建草稿 - 调用 API 创建草稿到公众号
- 输出结果 - 显示 media_id 和管理链接
- Load Configuration - Load configuration from EXTEND.md and .env
- Process Input - Read Markdown/HTML file, plain text is saved automatically
- Parse Metadata - Extract title, author, summary, cover from frontmatter
- Convert Format - Convert Markdown to WeChat-compatible HTML, apply theme styles
- Get Token - Obtain access_token via API
- Upload Images - Upload cover and body images, replace URLs
- Create Draft - Call API to create draft in Official Account
- Output Result - Display media_id and management link
前置要求
Prerequisites
- Node.js 18+ 或 Bun
- 微信公众号 AppID 和 AppSecret
- 公众号已开通开发者权限
- 服务器 IP 已添加到 API 白名单
- Node.js 18+ or Bun
- WeChat Official Account AppID and AppSecret
- Official Account has developer permissions enabled
- Server IP has been added to API whitelist
依赖安装
Dependency Installation
使用 Bun(推荐)
Using Bun (Recommended)
首次运行时,Bun 会自动安装依赖:
bash
bun skills/yy-post-to-wx/scripts/main.ts <file>Bun will automatically install dependencies on first run:
bash
bun skills/yy-post-to-wx/scripts/main.ts <file>使用 Node.js
Using Node.js
需要手动安装依赖:
bash
cd skills/yy-post-to-wx/scripts
npm install
cd ../../..Need to install dependencies manually:
bash
cd skills/yy-post-to-wx/scripts
npm install
cd ../../..环境检查
Environment Check
首次使用前建议运行环境检查:
bash
bun skills/yy-post-to-wx/scripts/check-permissions.ts检查内容:
- Bun 运行时
- 环境变量配置
- API 凭证是否存在
It is recommended to run the environment check before first use:
bash
bun skills/yy-post-to-wx/scripts/check-permissions.tsCheck items:
- Bun runtime
- Environment variable configuration
- Whether API credentials exist
依赖
Dependencies
- - Markdown 解析
marked - - frontmatter 解析
front-matter
- - Markdown parsing
marked - - frontmatter parsing
front-matter
限制
Limitations
- 不支持浏览器自动化发布(仅 API 方式)
- 不支持多账号管理
- 图片大小需符合微信公众号限制
- Does not support browser automation publishing (API-only)
- Does not support multi-account management
- Image size must comply with WeChat Official Account restrictions