SuperAPI AI Directory

wechat-article-maker

Writing & research

View repository

Updated 10-15 19:55

About this skill

WeChat Official Account Article Creation and Publishing

Language

Match the user's language: Respond in the language the user uses. If the user uses Chinese, respond in Chinese; if they use English, respond in English.

Directory Structure

wechat-article-maker/
├── scripts/                  # TypeScript 源文件
│   ├── wechat-api.ts        # API 发布逻辑
│   ├── wechat-article.ts    # 浏览器发布逻辑
│   ├── wechat-browser.ts    # 图文发布逻辑
│   ├── image-utils.ts       # 图片处理工具(sharp 集成)
│   ├── base64-utils.ts      # Base64 图片提取工具
│   ├── generate-cover.ts    # 封面生成逻辑
│   ├── md-to-wechat.ts      # Markdown 转换逻辑
│   ├── summary-utils.ts     # 文章摘要工具
│   ├── ensure-deps.ts       # 依赖自动安装
│   └── md/                  # Markdown 渲染引擎
│       ├── render.ts
│       ├── themes/          # 主题样式
│       └── extensions/      # 扩展插件
├── templates/                # 🆕 文章创作模板库
│   ├── opening_patterns.md  # 开篇模式库
│   ├── closing_patterns.md  # 结尾模式库
│   ├── language_rules.md    # 语言风格规则
│   └── structure_guide.md   # 结构模板
├── styles/                   # 🆕 文章样式
│   └── base_style.css       # 基础样式
├── examples/                 # 🆕 示例文章
│   ├── beginner_article.html
│   ├── intermediate_article.html
│   └── advanced_article.html
├── references/              # 参考文档
├── SKILL.md                 # 技能文档
├── package.json             # 依赖锁定
└── README.md                # 项目说明

Agent Execution: Determine this SKILL.md directory as SKILL_DIR, all commands run via npx -y bun :

How to Run

# 设置技能目录
SKILL_DIR="${SKILL_DIR}"

# 所有脚本通过 npx -y bun 运行(跨平台统一)
npx -y bun "${SKILL_DIR}/scripts/wechat-api.ts" article.md --inline-css
npx -y bun "${SKILL_DIR}/scripts/md-to-wechat.ts" article.md --theme grace
npx -y bun "${SKILL_DIR}/scripts/generate-cover.ts" --title "标题" --output cover.jpg

Automatic Dependency Installation: The script automatically detects and installs required dependencies on first run, no manual action needed.

Dependency Installation

Automatic Installation: All dependencies are automatically installed on the script's first run, no manual action needed.

Runtime Requirements:

  • ✅ Bun (recommended, used via npx -y bun )

Core Dependencies(automatically installed):

  • front-matter - Frontmatter parsing
  • highlight.js - Code highlighting
  • marked - Markdown rendering engine
  • reading-time - Reading time calculation
  • juice - CSS inline conversion

Optional Dependencies(cover image generation):

  • @napi-rs/canvas - High-performance image generation
  • sharp - Image processing library

Dependency Notes:

  • sharp will automatically install via scripts/ensure-deps.ts on first run
  • If optional dependencies are not installed,generate-cover will automatically generate an SVG format cover image (also supported by WeChat)

Feature Overview

This skill provides a WeChat Official Account article workflow withdual capabilities:

Mode A: Full Creation Workflow

关键词/URL → AI生成 → HTML → 图片清洗 → 发布
  1. AI Content Generation: Intelligently generate articles based on keywords or links
  2. Template-Driven Creation: Built-in opening, ending, and language style templates
  3. Parameterized Configuration: Supports multi-dimensional configuration such as length, depth, and style

Mode B: Direct Publishing Workflow

HTML/MD文件/链接 → 清洗 → 发布(跳过生成)
  1. Link Publishing Mode: Download an article link, process and publish
  2. Markdown Conversion: Built-in Markdown to HTML conversion, supports multiple themes
  3. Direct HTML Publishing: Process and publish existing HTML files
  4. Image Processing: Automatically download, clean metadata, and comply with WeChat specifications
  5. Style Conversion: Automatically convert CSS to inline styles
  6. One-Click Publishing: Supports both API (fast) and browser (visual) methods

Preferences (EXTEND.md)

Use Bash to check for the existence of EXTEND.md (priority order):

# 检查项目级别
test -f .awesome-skills/wechat-article-maker/EXTEND.md && echo "project"

# 检查用户级别(跨平台:$HOME 在 macOS/Linux/WSL 上都可用)
test -f "$HOME/.awesome-skills/wechat-article-maker/EXTEND.md" && echo "user"

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

┌───────────┬───────────────────────────────────────────────────────────────────────────┐ │ Result │ Action │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ Found │ Read, parse, and apply settings │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ Not found │ Use default values │ └───────────┴───────────────────────────────────────────────────────────────────────────┘

EXTEND.md supports: default theme | default publishing method (api/browser) | default author | Chrome profile path

Workflow selection

Based on user inputautomatically identifyand select the workflow:

Input type Identification method Workflow Whether to generate
Text content Does not contain links, and is not a file path Workflow 1: Content creation ✅ Generation required
Text + reference links Contains links, but the main body is a text description Workflow 1: Content creation (including link analysis) ✅ Generation required
Keyword Explicitly say "write an article about X" Flow 1: Content Creation ✅ Generation required
Single article link Contains only a URL, or say "publish this article" Flow 2: Link Publishing ❌ Skip generation
Markdown file Ending with .md file path Flow 3: Markdown Publishing ❌ Skip generation
HTML file Ending with .html file path Flow 4: HTML Publishing ❌ Skip generation

Recognition examples

用户输入                                    →  自动识别
─────────────────────────────────────────────────────────────
"写一篇关于 Docker 的文章"                   →  流程1(创作)
"帮我生成一篇介绍 MCP 的技术文章"             →  流程1(创作)
"https://blog.example.com/docker-tutorial"   →  流程2(链接发布)
"发布这个链接到公众号:https://..."           →  流程2(链接发布)
"./articles/my-article.md"                   →  流程3(MD发布)
"发布 ./posts/tutorial.html"                 →  流程4(HTML发布)

User explicit specification

If automatic recognition is uncertain, use AskUserQuestion to confirm:

header: "操作类型"
选项:
- 创作新文章 - 基于输入内容生成文章
- 直接发布 - 跳过生成,直接处理并发布

Flow 1: Content Creation and Publishing (AI-generated)

Use this flow when the user inputs text content, keywords, or content with reference links.

Creation progress checklist

Copy this checklist and check off items as you complete them:

内容创作进度:
- [ ] 步骤 0: 加载偏好设置
- [ ] 步骤 1: 识别输入类型
- [ ] 步骤 2: 信息收集(关键词/URL)
- [ ] 步骤 3: 询问创作参数
- [ ] 步骤 4: 选择结构模板
- [ ] 步骤 5: 撰写开篇
- [ ] 步骤 6: 撰写主体内容
- [ ] 步骤 7: 撰写结尾
- [ ] 步骤 8: 生成 HTML
- [ ] 步骤 9: 质量检查
- [ ] 步骤 10: 用户确认
- [ ] 步骤 11: 图片处理与发布
- [ ] 步骤 12: 完成报告

Step 0: Load preferences

Check and load EXTEND.md settings (see the preferences section above).

Step 1: Identify input type

Determine based on the input content:

  1. Keyword input: the user says "write an article about X"
  2. URL input: the user provides a link as reference material
  3. Text content: the user provides specific creation requirements

Step 2: Information gathering

If it is a keyword

  1. Use WebSearch to search the keyword, obtain 3-5 high-quality reference materials
  2. Collect information:
    • Core concepts and definitions
    • Main features and functions
    • Use cases and examples
    • Best practices and recommendations
    • Common problems and solutions

If it is a URL link

  1. Use WebFetch to read the URL content
  2. Extract:
    • Core viewpoints and themes
    • Article structure and logic
    • Key information and data
    • Code examples and cases
  3. Use WebSearch to supplement background knowledge

Step 3: Ask for creation parameters

Use AskUserQuestion to ask:

文章创作配置

问题1:文章风格
header: "风格"
选项:
- guide(指南型)- 全面系统,多角度讲解(推荐)
- tutorial(教程型)- 步骤清晰,循序渐进
- analysis(分析型)- 深入透彻,对比分析
- story(故事型)- 情境代入,经验分享

问题2:文章长度
header: "长度"
选项:
- short(2000-3000字)- 快速阅读
- medium(3000-5000字)- 平衡深度与可读性(推荐)
- long(5000-8000字)- 深度长文

问题3:技术深度
header: "深度"
选项:
- beginner(入门)- 多用比喻,减少术语
- intermediate(中级)- 平衡理论与实践(推荐)
- advanced(高级)- 深入细节,专业术语

问题4:是否包含代码示例
header: "代码"
选项:
- true - 包含可运行的代码示例
- false - 仅文字描述

问题5:是否进行网络调研
header: "调研"
选项:
- true - 使用 WebSearch 调研关键词(推荐)
- false - 仅基于已有知识生成

Step 4: Select a structure template

Select a template based on the style parameter (see templates/structure_guide.md):

guide - most commonly used:

# [标题]

[开篇引入 - 痛点场景]

---

## 什么是[X]?

[概念介绍 + 比喻说明]

---

## [X]有什么厉害之处?

### [特性1]
[说明 + 实例]

### [特性2]
[说明 + 实例]

### [特性3]
[说明 + 实例]

---

## 怎么使用[X]?

### [方式1]
[详细说明 + 代码示例]

### [方式2]
[详细说明 + 代码示例]

---

## 实战案例

### 案例一:[场景]
[背景 + 问题 + 解决方案 + 效果]

### 案例二:[场景]
[背景 + 问题 + 解决方案 + 效果]

---

## [X]适合谁用?

### 如果你是[角色1]
[适用说明]

### 如果你是[角色2]
[适用说明]

---

## 写在最后

[总结 + 金句 + 互动]

tutorial:

# [标题]

[开篇引入 - 痛点场景]

---

## 准备工作

[环境要求]
[前置知识]
[工具安装]

---

## 步骤一:[步骤名称]

[详细说明]
[代码示例]
[注意事项]

---

## 步骤二:[步骤名称]

[详细说明]
[代码示例]
[注意事项]

---

## 常见问题

### 问题1:[问题描述]
[解决方案]

---

## 写在最后

[总结 + 行动号召 + 互动]

analysis、story templates, see templates/structure_guide.md

Step 5: Write the opening

Must follow the template(see templates/opening_patterns.md):

Standard opening pattern:

你有没有遇到过这种情况?

[痛点1: 具体场景描述,用口语化表达]

[痛点2: 具体场景描述,用口语化表达]

[痛点3: 具体场景描述,用口语化表达]

说实话,我之前也是这样。

直到我发现了一个[解决方案]——**[主题]**。

[一句话核心价值说明]。

Opening requirements:

  • Must use "Have you ever encountered this situation?"
  • List 2-3 pain points (specific scenarios, not abstract descriptions)
  • Must include "To be honest, I used to be like this too"
  • Opening length: 100-150 characters

Step 6: Write the main content

Language style requirements(see templates/language_rules.md):

  1. Colloquial expression(Required):

    • Use "to be honest", "actually", "simply put"
    • Use "you", "I" first and second person
    • Mainly short sentences, each sentence no more than 30 characters
  2. Metaphors and analogies(At least 3):

    • "Just like...", "as if..."
    • Use everyday life things to metaphorize technical concepts
  3. Rhetorical questions and interrogative sentences(Use appropriately)

  4. Emoji(No more than 2 per paragraph):

    • ✅ ❌ 🔧 💡 🔍 ⚠️

Paragraph writing specifications:

  • Each paragraph 3-5 lines, avoid large blocks of text
  • Important data in a separate paragraph and bolded
  • Punchlines in a separate paragraph, within 20 characters

Title generation specifications:

The article title must contain at least 3 of the following 5 characteristics:

Characteristic Description Example
Clear pain point Directly address the target reader's specific troubles "Still manually editing code? This tool boosts your development efficiency by 300%"
Number appeal Use specific numbers to increase credibility "I spent 3 months and compiled 1000 Python tips"
Result-oriented Promise quantifiable benefits or changes "Learn this trick, and your code review pass rate increases by 90%"
Emotional appeal Stimulate curiosity, urgency, or resonance "Never write code like this again! The consequences are serious"
Suspense setup Create suspense to trigger the desire to click "Debugging tips that 99% of programmers don't know"

Step 7: Write the ending

Must follow the template(See templates/closing_patterns.md):

Standard ending pattern:

## 写在最后

[总结要点,2-3句]

[价值提炼,1-2句]

> [金句,一句话朗朗上口]

---

💬 **[互动问题]?**

评论区聊聊~

如果这篇文章对你有帮助,点个**在看**让更多人看到吧 👇

Ending requirements:

  • Must have a "## In conclusion" heading
  • Summary no more than 150 characters
  • Punchline catchy, no more than 20 characters
  • Must have an interactive question
  • Must have a call to like and watch

Step 8: Generate HTML

Output a complete HTML document, including inline CSS styles (refer to styles/base_style.css):

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[文章标题]</title>
    <style>
        body {
            font-family: Optima, "Microsoft YaHei", PingFangSC-regular, serif;
            font-size: 16px;
            line-height: 1.8;
            color: rgb(89, 89, 89);
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }

        h1 {
            font-size: 24px;
            color: rgba(53, 179, 120, 1);
            font-weight: bold;
            margin: 30px 0 15px;
        }

        h2 {
            font-size: 18px;
            color: rgb(255, 255, 255);
            background: rgb(0, 0, 0);
            padding: 2px 10px;
            font-weight: bold;
            margin: 30px 0 15px;
        }

        h3 {
            font-size: 20px;
            color: rgb(53, 179, 120);
            font-weight: bold;
            margin: 30px 0 15px;
        }

        strong {
            color: rgb(53, 179, 120);
            font-weight: bold;
        }

        blockquote {
            margin: 20px 0;
            padding: 10px 10px 10px 20px;
            border-left: 3px solid rgb(53, 179, 120);
            background: rgb(251, 249, 253);
        }

        code {
            font-family: Consolas, Monaco, Menlo, monospace;
            font-size: 14px;
            background: rgba(27, 31, 35, 0.05);
            padding: 2px 4px;
            border-radius: 4px;
            color: rgba(30, 107, 184, 1);
        }

        pre {
            background: #282c34;
            padding: 15px;
            border-radius: 5px;
            overflow-x: auto;
            margin: 10px 0;
        }

        pre code {
            background: none;
            padding: 0;
            color: #abb2bf;
        }
    </style>
</head>
<body>

[文章内容,转为HTML标签]

</body>
</html>

⚠️ Important: Code block format specifications

Code blocks must use the standard <pre><code> tags,It is forbidden to use <section> or other tags to simulate code blocks:

✅ Correct format:

<pre><code class="language-json">{
  "name": "example"
}</code></pre>

❌ Incorrect format(not supported):

<!-- 禁止使用 section 模拟代码块 -->
<section style="background: #f6f8fa; padding: 15px; ...">
{<br>
  "name": "example"<br>
}
</section>

Language identifier:

  • Must add to the <code> tag class="language-xxx" attribute
  • Supported languages:json, jsonc, javascript, typescript, python, bash, go, rust, java, c, cpp, sql , etc.
  • Example:<code class="language-python">, <code class="language-bash">

Automated processing:

  • Markdown to HTML: standard <pre><code> format is automatically used (no manual intervention required)
  • Non-standard format:wechat-api.ts will attempt to automatically identify and convert background: #f6f8fa to <section> tags

Step 9: Quality check

Content check:

  • The article length meets the length parameter requirements
  • Technical depth matches the depth parameter positioning
  • Article structure matches the style parameter template
  • All technical concepts are accurate

Style check:

  • Opening uses the pain point introduction pattern
  • Includes colloquial expressions such as "to be honest"
  • Uses the first person "I"
  • Includes at least 3 metaphors or analogies
  • Ending has a punchline and interaction
  • Emojis are used appropriately (≤2 per paragraph)

Format check:

  • H2 headings are used correctly (white text on black background)
  • Code examples have explanatory comments
  • Images have alt text and captions
  • HTML format is complete
  • CSS styles are complete

Readability check:

  • Sentences are short (≤30 characters per sentence)
  • Paragraphs are clear and topics are well-defined
  • Logic is coherent and consistent throughout

Step 10: Save file and confirm with user

  1. Save the HTML file:
# 生成 slug(文件名)
title="文章标题"
slug=$(echo "$title" | \
  iconv -t ascii//TRANSLIT 2>/dev/null | \
  tr '[:upper:]' '[:lower:]' | \
  tr ' ' '-' | \
  tr -cd '[:alnum:]-' | \
  cut -c1-50)

# 创建目录并保存
output_dir="wechat-articles/$(date +%Y-%m-%d)"
mkdir -p "$output_dir"
echo "$html_content" > "$output_dir/$slug.html"
  1. Ask the user for the next step:

Use AskUserQuestion:

header: "下一步"
选项:
- 直接发布 - 转换为微信格式并发布(推荐)
- 修改内容 - 说明需要调整的部分
- 仅保存文件 - 不发布,稍后手动处理

Step 11: Image processing and publishing

If the user chooses to publish directly:

  1. Process images:

    • Automatically download remote images in the HTML
    • Clean image metadata (using sharp)
    • Upload to the WeChat material library
  2. CSS inlining conversion(if needed):

    npx -y bun "${SKILL_DIR}/scripts/wechat-api.ts" \
      "$output_dir/$slug.html" \
      --inline-css
    
  3. Prepare the cover image(mandatory rule):

    • Priority 1: Explicitly specified (featureImage/coverImage in frontmatter)
    • Priority 2: Automatically extract the first image in the article
    • Priority 3: Automatically generate (AI or script)
  4. Publish to WeChat:

    • API method (recommended)
    • Browser method

Step 12: Completion report

✓ 微信公众号文章创作与发布完成!

创作信息:
• 输入类型:关键词/URL
• 文章风格:guide
• 文章长度:3500字
• 技术深度:intermediate

发布信息:
• 标题:[标题]
• 封面:自动生成
• 图片:3张(已清洗)

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

下一步:
→ 管理草稿:https://mp.weixin.qq.com

生成的文件:
• $output_dir/$slug.html(HTML 文件)

Process 2: Link article publishing (direct publishing)

When the user provides a single article link,skip the generation stage, and directly download, clean, and publish.

Publishing progress checklist

链接发布进度:
- [ ] 步骤 0: 加载偏好设置
- [ ] 步骤 1: 链接验证
- [ ] 步骤 2: 文章下载与解析
- [ ] 步骤 3: 图片下载与清洗
- [ ] 步骤 4: 样式转换(CSS 内联)
- [ ] 步骤 5: 用户确认
- [ ] 步骤 6: 准备封面图
- [ ] 步骤 7: 执行发布
- [ ] 步骤 8: 完成报告

No generation step: directly process the original content and publish.

Detailed steps

Refer to Process 2 in the original SKILL.md (unchanged, starting from line 588).


Process 3: Markdown file publishing (direct publishing)

When the user provides a .md file,skip the generation stage, and directly render, process, and publish.

Quick publish

# 一键转换并发布
npx -y bun "${SKILL_DIR}/scripts/md-to-wechat.ts" \
  "$markdown_file" \
  --theme grace \
  --output ./output

# 然后使用 API 发布
npx -y bun "${SKILL_DIR}/scripts/wechat-api.ts" \
  "$html_output" \
  --inline-css \
  --cover "$cover_image"

Step description

  1. Parse Markdown: extract frontmatter (title, author, summary, etc.)
  2. Convert to HTML: apply theme styles
  3. Process images: download remote images and replace with local paths
  4. Publish: same as step 11 in Process 1

No generation step: directly render and publish.


Process 4: HTML file direct publishing

When the user provides a .html file,skip all processing stages, and publish directly.

Quick publish

# 直接发布(自动内联 CSS)
npx -y bun "${SKILL_DIR}/scripts/wechat-api.ts" \
  "$html_file" \
  --title "文章标题" \
  --summary "摘要" \
  --cover "$cover_image" \
  --inline-css

Note: You must use the --inline-css parameter, otherwise the styles will be lost.

No generation step: Publish directly.


Image-text publishing (image-text message)

Used to publish short content + multiple images (up to 9 images).

How to use

# 从 Markdown 文件发布
npx -y bun "${SKILL_DIR}/scripts/wechat-browser.ts" \
  --markdown article.md \
  --images ./images/

# 直接指定内容和图片
npx -y bun "${SKILL_DIR}/scripts/wechat-browser.ts" \
  --title "标题" \
  --content "内容" \
  --image img1.png \
  --image img2.png \
  --submit

See also:references/image-text-posting.md


Template library

This skill has a built-in complete article creation template library, located in the templates/ directory.

Opening pattern library

File:templates/opening_patterns.md

Contains 4 opening patterns:

  1. Pain point scenario introduction(most commonly used) - suitable for tool introductions and problem solving
  2. Contrastive introduction - suitable for comparison and optimization articles
  3. Question-based introduction - suitable for feature introductions and new feature releases
  4. Story-based introduction - suitable for case analysis and experience sharing

Ending pattern library

File:templates/closing_patterns.md

Contains 4 ending patterns:

  1. Value summary type(most commonly used) - summary + memorable quote + interaction
  2. Call to action type - emphasizes practice and action
  3. Future outlook type - trend analysis and future outlook
  4. Key point extraction type - knowledge-intensive articles that help with memory

Language style rules

File:templates/language_rules.md

Core principles:

  • Prioritize colloquialism (use "to be honest", "actually", etc.)
  • First-person narration (build emotional connection)
  • Use many metaphors and analogies (lower the threshold for understanding)
  • Rhetorical and interrogative sentences (enhance interactivity)
  • Appropriate emojis (no more than 2 per paragraph)

Structure templates

File:templates/structure_guide.md

Contains detailed templates for 4 article structures:

  • guide (guide type)
  • tutorial (tutorial type)
  • analysis (analysis type)
  • story (story type)

Style file

File:styles/base_style.css

Defines the unified styles for articles:

  • Main color: #35B378 (green)
  • H1: green 24px bold
  • H2: black background with white text 18px
  • H3: green 20px bold
  • Body text: 15px dark gray, line height 1.8

Example articles

Located in the examples/ directory:

  • beginner_article.html - introductory in-depth example
  • intermediate_article.html - intermediate in-depth example
  • advanced_article.html - advanced in-depth example

Theme styles

Built-in three themes (located in scripts/md/themes/):

default - classic theme

  • Traditional layout style
  • Centered title with bottom border decoration
  • Secondary heading: white text on colored background
  • Suitable for: formal articles, industry reports

grace - elegant theme (recommended)

  • Text with soft shadows
  • Rounded card-style quote blocks
  • Refined list styles
  • Suitable for: popular science articles, personal blogs

simple - minimalist theme

  • Modern minimalist style
  • Asymmetric rounded corner design
  • Fresh and airy whitespace
  • Suitable for: tutorials, short articles

Custom Themes

  1. In scripts/md/themes/ create a new CSS file
  2. Based on base.css extend styles
  3. Use --theme <name> parameter to apply

Configuration and Environment

Environment Variables

Configuration is loaded from the following locations (in descending order of priority):

  1. Environment variables
  2. <cwd>/.awesome-skills/.env
  3. ~/.awesome-skills/.env

Required environment variables (API publishing method):

WECHAT_APP_ID=your_app_id
WECHAT_APP_SECRET=your_app_secret

Optional environment variables:

WECHAT_BROWSER_CHROME_PATH=/path/to/chrome  # 自定义 Chrome 路径

EXTEND.md Configuration Example

# wechat-article-maker 配置

## 默认设置

- 主题:grace
- 发布方式:api
- 作者:AI爱好者
- Chrome 配置文件:~/.chrome-wechat

## 自动操作

- 自动生成封面:true
- 自动清洗图片:true
- 自动内联样式:true

Technical Details

Markdown Rendering Engine

Uses markdown-it and extensions (located in scripts/md/):

  • Basic rendering:render.ts
  • Extension plugins:
    • alert.ts - GitHub-style callouts
    • footnotes.ts - Footnote support
    • katex.ts - Math formulas
    • toc.ts - Table of contents generation
    • infographic.ts - Infographics
    • ruby.ts - Ruby annotations
    • slider.ts - Sliders
    • plantuml.ts - UML diagrams

Image Processing Algorithms

Base64 Image Extraction(scripts/base64-utils.ts):

Automatically detects and processes base64 images embedded in HTML:

  1. Smart detection: Scans HTML content, identifies images in <img src="data:image/...;base64,..."> format
  2. Automatic extraction: Decodes base64 data and saves it as a local file (extracted-images/base64-*.jpg)
  3. Path replacement: Replaces data URIs with relative file paths for subsequent upload to WeChat
  4. Hash naming: Uses MD5 hashing to generate unique filenames, avoiding duplication and conflicts

Processing Example:

<!-- 原始 HTML -->
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBD..." alt="示例图片">

<!-- 处理后 -->
<img src="extracted-images/base64-0-a1b2c3d4.jpg" alt="示例图片">

Metadata Cleaning(scripts/image-utils.ts):

The built-in sharp library provides reliable image processing capabilities:

  1. Smart detection: Scans the first 2KB of the image, detecting non-standard metadata markers such as AIGC/Coze/Adobe
  2. Deep cleaning: Re-encodes JPEG using sharp, completely removing all metadata
  3. Automatic fallback: When sharp is unavailable, uses manual parsing as a backup solution
  4. Dimension optimization: Automatically resizes oversized images (limited to 1920x1080) to comply with WeChat specifications

Dual-Engine Cleaning Strategy:

Method Priority Description
Sharp re-encoding Preferred Fully re-encodes the image, removing 100% of metadata
Manual parsing Fallback Parses JPEG segment structure, skipping non-standard markers

Automatic Retry Logic:

try {
  await uploadImage(imageBuffer);
} catch (error) {
  if (error.code === 40113) {
    // 强制使用 sharp 深度清理后重试
    const cleanedBuffer = await cleanImage(imageBuffer, true);
    await uploadImage(cleanedBuffer);
  }
}

CSS Inlining Conversion

Uses the juice library to convert CSS rules into inline styles:

Before:

<style>
  h1 { color: blue; font-size: 24px; }
</style>
<h1>标题</h1>

After:

<h1 style="color: blue; font-size: 24px;">标题</h1>

Why it's needed: The WeChat Official Account editor does not support <style> tags and only accepts inline styles.

Cover Image Generation

Method 1: Multimodal LLM generation (recommended)

If the Agent has text-to-image capability, prioritize generating customized cover images based on article content.

Method 2: Pure Node.js (no system dependencies)

Script:scripts/generate-cover.ts

npx -y bun "${SKILL_DIR}/scripts/generate-cover.ts" \
  --title "文章标题" \
  --output cover.jpg \
  --gradient-start "#667eea" \
  --gradient-end "#764ba2"

Features:

  • ✓ No ImageMagick required
  • ✓ Supports multiple image libraries (@napi-rs/canvas, sharp, SVG)
  • ✓ Automatically wraps long titles
  • ✓ Customizable colors and sizes
  • ✓ Cross-platform (Node.js/Bun)

Feature Comparison

Feature Flow 1: Content Creation Flow 2: Link Publishing Flow 3: MD Publishing Flow 4: HTML Publishing Image-Text Publishing
Input Type Text/Keywords/URL Single Link .md File .html File Short Text + Images
Whether Generated ✅ Yes ❌ No ❌ No ❌ No ❌ No
AI Creation ✅ ❌ ❌ ❌ ❌
Content Understanding ✅ ✅ ❌ ❌ ❌
Markdown Conversion ✅ ❌ ✅ ❌ ✅
Theme Styles ✅ generator styles Keep as-is ✅ 3 themes Keep as-is ❌
Image Cleaning ✅ ✅ ✅ ✅ ❌
CSS Inlining ✅ ✅ ✅ ✅ ❌
Cover Generation ✅ ✅ ✅ ✅ ❌
API Publishing ✅ ✅ ✅ ✅ ❌
Browser Publishing ✅ ✅ ✅ ✅ ✅
Use Cases Original Content Repost/Share Local Articles Ready-made HTML Image Display

Troubleshooting

Issue Solution
Dependencies not installed Dependencies are automatically installed on first run
Cannot find module Try running the command again; missing dependencies will be installed automatically
Cover image generates SVG instead of PNG/JPEG Optional dependency not installed, run cd ${SKILL_DIR}/scripts && npm install @napi-rs/canvas or accept the SVG format
Link inaccessible Check network connection, try using a proxy or VPN
Image upload failed (40113) sharp automatically performs deep metadata cleanup and retries; no manual handling needed
Styles lost Make sure the --inline-css parameter is used
API error 40001 access_token is invalid or expired, check API credentials
API error 40164 (invalid ip) Add the server IP to the whitelist in the WeChat Official Account backend: mp.weixin.qq.com → Development → Basic Configuration → IP Whitelist
Chrome not found Set the environment variable WECHAT_BROWSER_CHROME_PATH
Title/summary missing Manually specify the --title and --summary parameters
Paste failed (browser method) Check system clipboard permissions
Markdown conversion error Check the Markdown syntax and make sure the frontmatter format is correct

Best Practices

1. Content Creation

  • ✓ Provide a clear creative intent and target audience
  • ✓ When citing links, explain how they are used (in-depth analysis vs brief mention)
  • ✓ Preview before publishing to avoid rework
  • ✓ Save the source file for easier later edits
  • ✓ The title must contain at least 3 characteristics: clear pain point, attractive numbers, results-oriented, emotional engagement, suspense setup
  • ✓ Keep paragraphs to 3-5 lines, and put important data in its own bolded paragraph
  • ✓ Put key quotes in their own paragraph, keep them within 20 characters for easier sharing

2. Link publishing

  • ✓ Confirm the link is accessible (avoid pages that require login)
  • ✓ Check the quality of the original images (replace blurry images)
  • ✓ Prefer the API method (fast and reliable)
  • ✓ Preview the processed HTML before publishing

3. Style and formatting

  • ✓ For professional articles, use the default theme
  • ✓ For general content, use the grace theme (recommended)
  • ✓ For tutorials, use the simple theme
  • ✓ Ensure image clarity (2x resolution recommended)
  • ✓ Use a 2:1 ratio for cover images (900x500px)

4. Publishing process

  • ✓ Configure API credentials on first use
  • ✓ Preview in the drafts box before publishing
  • ✓ Keep the source files (markdown/html) for later edits
  • ✓ Regularly back up published articles

5. Image processing

  • ✓ Use high-quality original images (avoid recompression)
  • ✓ Use moderate image sizes (width 800-1200px)
  • ✓ Keep file size within 1MB
  • ✓ If there are AIGC images, let the script clean them automatically

Usage examples

Example 1: Create a new article (requires generation)

用户:创作一篇关于 Docker 容器化的文章

Agent:
✓ 识别为内容创作模式
✓ WebSearch 调研关键词
✓ 询问参数
✓ 生成 3500 字文章(guide风格,中级深度)
✓ 转换为 HTML
✓ 清洗图片
✓ 发布到微信

结果:草稿已保存(media_id: abc123...)

Example 2: Publish a linked article (skip generation)

用户:发布这篇文章到公众号:https://blog.example.com/docker

Agent:
✓ 识别为链接发布模式
✓ 下载文章 HTML 和 3 张图片
✓ 清洗图片元数据
✓ CSS 内联转换
✓ 展示处理结果
✓ 用户确认
✓ 发布到微信

结果:草稿已保存(无生成步骤)

Example 3: Publish a Markdown file (skip generation)

用户:发布 ./articles/docker-tutorial.md

Agent:
✓ 识别为 Markdown 发布模式
✓ 解析 frontmatter
✓ 渲染 HTML(grace 主题)
✓ 下载 2 张远程图片
✓ 自动生成封面
✓ 发布到微信

结果:草稿已保存(无生成步骤)

Permission requirements

  • Network access: fetch link content, download images
  • File read/write: save articles, images, and configuration
  • Environment variables: read WeChat API credentials
  • External commands: call bun/npx to run TypeScript scripts
  • Browser(optional): Chrome for the browser publishing method

Dependencies and license

Core dependencies

  • Bun/Node.js: run TypeScript scripts (Node.js >= 18.0.0)
  • npm/bun: package manager (used to install dependencies)

Automatically installed dependencies

On first run, the script automatically installs the following dependencies via scripts/ensure-deps.ts :

Required packages:

  • front-matter - Frontmatter parsing
  • highlight.js - Code highlighting
  • marked - Markdown rendering engine
  • reading-time - Reading time calculation
  • juice - CSS inlining conversion library

Optional packages(cover image generation):

  • @napi-rs/canvas - High-performance image generation
  • sharp - Image processing library

Runtime dependencies (optional)

  • Chrome/Chromium: required for the browser publishing method
  • WeChat Official Account API credentials: required for the API publishing method

License

  • The Markdown rendering engine is based on the MIT License
  • Use of the WeChat Official Account API must comply with the WeChat Official Platform Service Agreement

Acknowledgements

This skill integrates the following features and technologies:

  • wechat-article-generator: AI article generation, template library, style system
  • wechat-article-writer: Content understanding and creation
  • baoyu-post-to-wechat: Publishing workflow and technical implementation
  • Markdown rendering: Based on marked and extension plugins
  • Style themes: References excellent WeChat Official Account layout practices
  • Image processing: JPEG metadata cleaning algorithm
  • WeChat API: Official documentation and best practices

Changelog

v2.0.0 (2026-03-24)

Major update: Integrated wechat-article-generator and wechat-article-maker

  • ✅ Added AI article generation capability (based on generator)
  • ✅ Added template library (opening, ending, language style, structure)
  • ✅ Added parameterized configuration (length, depth, style, code, research)
  • ✅ Retained standalone publishing capability (direct publishing via HTML/MD/link)
  • ✅ Optimized workflow recognition logic
  • ✅ Added package.json dependency locking
  • ✅ Added example articles

v1.0.3 (2026-02-10)

  • ✓ Optimized cover image rules: set as mandatory logic. When no cover is specified, if the article contains images, the first one is used by default; a default cover is only generated when the article has no images.

v1.0.2 (2026-02-10)

  • ✓ Optimized image selection strategy: prioritize using multimodal large models to generate high-quality cover images
  • ✓ Fixed md-to-wechat.ts script supports the --output parameter

v1.0.1 (2026-02-10)

  • ✓ Added 5 major principles for title generation (clear pain point, numeric appeal, result-oriented, emotional appeal, suspense setup)
  • ✓ Added article layout specifications (paragraph structure, image placement, code blocks, key quote design)
  • ✓ Optimized content creation workflow to improve article readability and shareability

v1.0.0 (2026-02-09)

  • ✓ Integrated content creation and link publishing features
  • ✓ Built-in Markdown to HTML converter
  • ✓ Supports three theme styles (default, grace, simple)
  • ✓ Automatic image metadata cleaning
  • ✓ Automatic CSS inlining conversion
  • ✓ Cover image generation (no system dependencies)
  • ✓ Two publishing methods: API and browser
  • ✓ Complete workflow and error handling

Skill version:2.0.0 Last updated:2026-03-24 Author: Integrated from wechat-article-generator, wechat-article-writer, and baoyu-post-to-wechat