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

  1. 获取微信公众号 API 凭证:
  2. 保存凭证到环境变量:
    • 项目级:创建
      .baoyu-skills/.env
      文件
    • 用户级:创建
      ~/.baoyu-skills/.env
      文件
env
WECHAT_APP_ID=your_app_id
WECHAT_APP_SECRET=your_app_secret
  1. 创建配置文件
    EXTEND.md
    (可选):
md
default_theme: default
default_color: blue
default_author: 你的名字
need_open_comment: 1
only_fans_can_comment: 0
  1. Obtain WeChat Official Account API credentials:
  2. Save credentials to environment variables:
    • Project-level: Create
      .baoyu-skills/.env
      file
    • User-level: Create
      ~/.baoyu-skills/.env
      file
env
WECHAT_APP_ID=your_app_id
WECHAT_APP_SECRET=your_app_secret
  1. Create configuration file
    EXTEND.md
    (optional):
md
default_theme: default
default_color: blue
default_author: Your Name
need_open_comment: 1
only_fans_can_comment: 0

配置项说明

Configuration Item Description

配置项说明默认值
default_theme
默认主题
default
default_color
默认颜色主题默认
default_author
默认作者
need_open_comment
是否开启评论
1
only_fans_can_comment
是否仅粉丝可评论
0
Configuration ItemDescriptionDefault Value
default_theme
Default theme
default
default_color
Default colorTheme default
default_author
Default authorEmpty
need_open_comment
Whether to enable comments
1
only_fans_can_comment
Whether only fans can comment
0

主题选项

Theme Options

  • default
    - 默认主题,简洁大方
  • grace
    - 优雅风格,更大行高
  • simple
    - 极简风格,去掉边框阴影
  • modern
    - 现代风格,卡片式设计
  • default
    - Default theme, concise and elegant
  • grace
    - Elegant style, larger line height
  • simple
    - Minimalist style, removes borders and shadows
  • modern
    - Modern style, card-based design

颜色预设

Color Presets

blue
,
green
,
vermilion
,
yellow
,
purple
,
sky
,
rose
,
olive
,
black
,
gray
,
pink
,
red
,
orange
也可以使用自定义 hex 颜色值,如
#ff0000
blue
,
green
,
vermilion
,
yellow
,
purple
,
sky
,
rose
,
olive
,
black
,
gray
,
pink
,
red
,
orange
Custom hex color values are also supported, such as
#ff0000
.

使用方法

Usage

bash
undefined
bash
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]
undefined
npx -y bun skills/yy-post-to-wx/scripts/main.ts <file> [options]
undefined

参数选项

Parameter Options

参数说明示例
<file>
输入文件路径
article.md
--theme <name>
主题名称
--theme grace
--color <color>
颜色名称或 hex
--color green
--title <title>
强制指定标题
--title "文章标题"
--summary <text>
强制指定摘要
--summary "这是一篇文章"
--author <name>
强制指定作者
--author 张三
--cover <path>
指定封面图片
--cover ./cover.png
--no-cite
禁用外链转底部引用
--no-cite
ParameterDescriptionExample
<file>
Input file path
article.md
--theme <name>
Theme name
--theme grace
--color <color>
Color name or hex
--color green
--title <title>
Force specify title
--title "Article Title"
--summary <text>
Force specify summary
--summary "This is an article"
--author <name>
Force specify author
--author Zhang San
--cover <path>
Specify cover image
--cover ./cover.png
--no-cite
Disable external link to bottom citation conversion
--no-cite

示例

Examples

bash
undefined
bash
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
undefined
bun skills/yy-post-to-wx/scripts/main.ts ./article.md --no-cite
undefined

工作流程

Workflow

  1. 加载配置 - 从 EXTEND.md 和 .env 加载配置
  2. 处理输入 - 读取 Markdown/HTML 文件,纯文本自动保存
  3. 解析元数据 - 从 frontmatter 提取标题、作者、摘要、封面
  4. 转换格式 - Markdown 转换为微信兼容 HTML,应用主题样式
  5. 获取 Token - 通过 API 获取 access_token
  6. 上传图片 - 上传封面和正文图片,替换 URL
  7. 创建草稿 - 调用 API 创建草稿到公众号
  8. 输出结果 - 显示 media_id 和管理链接
  1. Load Configuration - Load configuration from EXTEND.md and .env
  2. Process Input - Read Markdown/HTML file, plain text is saved automatically
  3. Parse Metadata - Extract title, author, summary, cover from frontmatter
  4. Convert Format - Convert Markdown to WeChat-compatible HTML, apply theme styles
  5. Get Token - Obtain access_token via API
  6. Upload Images - Upload cover and body images, replace URLs
  7. Create Draft - Call API to create draft in Official Account
  8. 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.ts
Check items:
  • Bun runtime
  • Environment variable configuration
  • Whether API credentials exist

依赖

Dependencies

  • marked
    - Markdown 解析
  • front-matter
    - frontmatter 解析
  • marked
    - Markdown parsing
  • front-matter
    - frontmatter parsing

限制

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