npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

multi-publisher

v1.1.4

Published

Markdown → 微信公众号 / 知乎 / 掘金等多平台 CLI 发布工具

Readme

multi-publisher

一行命令,Markdown 发布到全网。

将排版好的 Markdown 文章一键发布到微信公众号、知乎、掘金、CSDN 等 20+ 平台,无需手动复制粘贴。支持浏览器自动登录获取 Cookie,4 套精排渲染主题(按平台自动匹配),是内容创作者的效率神器。


功能特性

| 特性 | 说明 | | ------ | ------ | | 多平台支持 | 微信公众号、知乎、掘金、CSDN、微博、小红书、B站等 20+ 平台 | | 浏览器自动登录 | Playwright 驱动扫码/账号登录,Cookie 自动获取保存 | | 4 套精排主题 | default(通用)、wechat(公众号)、modern(技术/知乎)、minimal(轻阅读/头条),均按平台自动匹配 | | 自动封面图生成 | AI 根据标题生成封面图,自动上传到微信 CDN | | Markdown 直发 | front-matter 元数据、代码高亮、LaTeX 公式 | | CI/CD 友好 | 纯命令行无需浏览器,配置文件统一管理 | | 草稿箱发布 | 微信公众号 → 草稿箱,其他平台 → 各自草稿箱 |


安装

# 推荐:一键安装(Node.js ≥ 18)
npm install -g multi-publisher

# 验证安装
mpub --version

Node.js ≥ 18 required.

配合 AI 使用

本工具已制作为 Claude Code Skill,可让 AI 直接帮你发布文章:

# 在任意 Claude Code 对话中,直接描述你的需求:
# "帮我把这篇 article.md 发布到微信公众号"
# "用 wechat 主题渲染预览一下"
# AI 会调用 mpub 完成操作

查看支持的所有命令:mpub --help


快速开始

配合 AI 使用:安装本工具后,在 Claude Code 中直接说"帮我发布文章到微信公众号",AI 会调用 mpub 自动完成。

1. 配置平台登录

方式一:浏览器自动登录(推荐)

# 登录知乎
mpub login -p zhihu

# 登录掘金
mpub login -p juejin

# 登录小红书
mpub login -p xiaohongshu

# 查看所有支持平台
mpub login --help

方式二:手动 Cookie 配置

# 交互式输入 Cookie
mpub cookie --platform zhihu --set

# 检查 Cookie 状态
mpub cookie --platform zhihu --check

2. 发布文章

# 发布到微信公众号(默认)
mpub publish -f article.md

# 发布到知乎草稿
mpub publish -f article.md -p zhihu

# 一键发布到所有已登录平台
mpub publish-all -f article.md

# 渲染预览(不发布)
mpub render -f article.md

# 指定主题渲染
mpub render -f article.md -t wechat

# 自动封面图(文章无封面时 AI 生成)
mpub publish -f article.md -p weixin --auto-cover

# 指定封面图
mpub publish -f article.md -p weixin -c cover.jpg

支持的平台

浏览器自动登录状态

| 平台 | 登录命令 | Cookie 获取 | 草稿发布 | 备注 | | ------ | ---------- | ------------- | ---------- | ------ | | 微信公众号 | mpub credential --set | ✅ | ✅ | AppID + AppSecret | | 知乎 | mpub login -p zhihu | ✅ | ✅ | 直接发布草稿 | | 掘金 | mpub login -p juejin | ✅ | ✅ | 直接发布草稿 | | CSDN | mpub login -p csdn | ✅ | ✅ | 直接发布草稿 | | 小红书 | mpub login -p xiaohongshu | ✅ | 🔄 测试中 | 需要更多测试 | | 简书 | mpub login -p jianshu | ✅ | ❌ 待实现 | | | 微博 | mpub login -p weibo | ✅ | ❌ 待实现 | | | 头条号 | mpub login -p toutiao | ✅ | 🔄 测试中 | 有反爬机制 | | 百家号 | mpub login -p baijiahao | ✅ | ❌ 待实现 | | | B站 | mpub login -p bilibili | ✅ | 🔄 测试中 | 需要更多测试 | | 思否 | mpub login -p segmentfault | ✅ | ❌ 待实现 | | | 博客园 | mpub login -p cnblogs | ✅ | ❌ 待实现 | | | 开源中国 | mpub login -p oschina | ✅ | ❌ 待实现 | | | 慕课网 | mpub login -p imooc | ✅ | ❌ 待实现 | | | 雪球 | mpub login -p xueqiu | ✅ | ❌ 待实现 | | | 人人都是产品经理 | mpub login -p woshipm | ✅ | ❌ 待实现 | | | 豆瓣 | mpub login -p douban | ✅ | ❌ 待实现 | | | 搜狐号 | mpub login -p sohu | ✅ | ❌ 待实现 | | | 东方财富 | mpub login -p eastmoney | ✅ | ❌ 待实现 | | | 51CTO | mpub login -p cto51 | ✅ | ❌ 待实现 | |

  • ✅ 已验证可用
  • 🔄 测试中,可能存在问题
  • ❌ 待实现,适配器框架已搭建但未测试发布功能

已验证平台

登录 + 草稿发布:知乎、掘金、CSDN、微信公众号

仅登录验证:小红书、微博、B站、头条号等(Cookie 获取成功,草稿发布待测试)

# 查看所有支持平台
mpub platforms

主题系统

🎨 4 套内置主题(按平台自动匹配)

mpub 内置 4 套浅色阅读主题,均针对公众号 / 知乎 / 头条等白底平台的真实排版规范做了优化:

| 主题 | 风格 | 适配平台 | | ------ | ------ | ---------- | | default | 通用简洁,绿调标题/引用 | 兜底,所有平台可用 | | wechat | 琥珀编辑风(Tufte 灵感):重点琥珀高亮、金句引用块、卡片容器 | 微信公众号 | | modern | 深色代码块、清晰层次(知乎/网页友好) | 知乎、技术博客 | | minimal | 极简留白、轻装饰 | 头条号等轻阅读平台 |

平台自动匹配:未用 -t 指定主题时,发布按平台自动选默认主题—— 微信 → wechat,知乎 → modern,头条 → minimal,其余回退 default。 (手动 -t 仍可覆盖。)

完整预览:themes/all-themes-preview.html(含卡片容器示例,重新生成:npx tsx scripts/generate-all-themes-preview.ts

卡片容器语法(:::tip / :::warning / :::note)

正文可用卡片容器突出重点——tip(重点,琥珀)、warning(警示,红)、note(说明,灰),标题可选,内部支持完整 Markdown:

:::tip 先记住结论
项目放对地方:warm build **2.63s**。
:::

:::warning 验证纪律
黑洞连接也能完成 TCP 握手——验证必须看真实业务效果。
:::

:::note 适合谁
纯轻编辑型 → Windows 原生也可。
:::

命令行预览:

mpub render -f article.md -t wechat
mpub render -f article.md -t modern
mpub render -f article.md -t minimal

全部 4 主题: default、wechat、modern、minimal

使用主题

# 不指定主题:发布到微信自动用 wechat,知乎自动用 modern
mpub publish -f article.md -p weixin
mpub publish -f article.md -p zhihu

# 渲染时手动指定主题
mpub render -f article.md -t wechat

# 发布时手动覆盖主题
mpub publish -f article.md -t modern -p zhihu

自定义主题

# 使用自定义 CSS 文件
mpub render -f article.md --custom-theme ./my-theme.css
/* my-theme.css 示例 */
body { font-family: 'PingFang SC', sans-serif; }
h1 { color: #1a1a1a; font-size: 1.5em; }
pre { background: #f6f8fa; border-radius: 6px; }

文章格式

front-matter 元数据

重要:front-matter 是必需的!缺少 front-matter 会导致标题显示为"无标题"。

---
title: 文章标题                      # 必填,用于公众号标题
author: 作者名                       # 必填
description: 文章描述(可选)          # 用于公众号摘要
cover: https://example.com/cover.jpg # 可选,有 --auto-cover 可省略
source_url: https://original.url     # 原文链接(可选)
tags: [技术, 前端, JavaScript]        # 标签(可选)
---

正文内容...

配置文件

所有配置存储在统一文件中,无分散文件

// ~/.config/multi-publisher/config.json (Linux/macOS)
// %APPDATA%/multi-publisher/config.json (Windows)
{
  "version": 1,
  "weixin": {
    "appId": "wx...",
    "appSecret": "..."
  },
  "zhihu": {
    "cookies": { "z_c0": "..." }
  },
  "juejin": {
    "cookies": { "uid_tt": "..." }
  }
}
# 查看配置文件路径
mpub credential --location

项目结构

src/
├── index.ts                    # CLI 入口,命令注册
├── config.ts                   # 统一配置管理(ConfigStore)
│
├── cli/                        # 命令行接口
│   ├── index.ts                # Commander.js 入口
│   ├── publish.ts              # publish 命令
│   ├── render.ts               # render 命令(预览)
│   ├── platforms.ts            # platforms 命令
│   ├── credential.ts           # credential 命令(微信凭据)
│   ├── cookie.ts               # cookie 命令(Cookie 管理)
│   ├── login.ts                # login 命令(浏览器自动登录)
│   └── publish-all.ts          # publish-all 命令
│
├── core/                       # 核心渲染引擎
│   ├── parser.ts               # Markdown + front-matter 解析
│   ├── renderer.ts             # 渲染管道(Markdown → HTML)
│   ├── styler.ts               # CSS 内联(juice)
│   ├── mathjax.ts              # LaTeX → SVG/PNG 公式
│   └── theme.ts                # 主题加载与切换
│
├── adapters/                   # 平台适配器
│   ├── interface.ts            # IPlatformAdapter 接口定义
│   ├── index.ts                # 适配器注册表
│   ├── base-adapter.ts         # 基础适配器
│   ├── registry.ts             # 平台注册与管理
│   ├── wechat-publisher.ts     # 微信公众号发布核心
│   ├── weixin.ts               # 微信公众号适配器
│   ├── zhihu.ts                # 知乎适配器
│   ├── juejin.ts               # 掘金适配器
│   └── ...                     # 其他平台适配器
│
└── runtime/                    # 运行时抽象
    ├── index.ts                # RuntimeInterface 接口
    ├── node-runtime.ts         # Node.js 运行时实现
    └── browser-runtime.ts       # Playwright 浏览器运行时

核心流程

Markdown 文件
    │
    ▼
┌─────────────┐    ┌──────────────┐    ┌────────────────┐
│  parser.ts  │───▶│ renderer.ts  │───▶│   styler.ts    │
│  front-matter│    │ AST → HTML   │    │ CSS 内联        │
│  Markdown 解析│    │ 代码高亮/LaTeX│    │ 主题应用        │
└─────────────┘    └──────────────┘    └────────────────┘
                                              │
                   ┌──────────────────────────┘
                   ▼
           ┌───────────────┐    ┌──────────────────────┐
           │ wechat-publish│    │   platform adapter   │
           │ 图片上传 → media_id│    │   调用平台 API 发布   │
           └───────────────┘    └──────────────────────┘

适配器接口

interface IPlatformAdapter {
  readonly meta: PlatformMeta      // 平台元信息
  init(runtime: RuntimeInterface): Promise<void>
  checkAuth(): Promise<AuthResult> // 认证检查
  publish(article: Article): Promise<SyncResult>  // 发布文章
}

开发

# 安装依赖
npm install

# 开发模式
npm run dev

# 构建
npm run build

# 类型检查
npm run typecheck

添加新平台

  1. src/adapters/ 创建 <platform>.ts,实现 IPlatformAdapter 接口
  2. src/adapters/index.ts 注册
// src/adapters/my-platform.ts
export class MyPlatformAdapter implements IPlatformAdapter {
  readonly meta: PlatformMeta = {
    id: 'myplatform',
    name: '我的平台',
    icon: 'https://...',
    homepage: 'https://...',
    capabilities: ['article', 'draft'],
  }
  // 实现 init / checkAuth / publish
}
// src/adapters/index.ts
export { MyPlatformAdapter } from './my-platform.js'
// 添加到导出列表

FAQ

Q: 微信公众号发布需要什么权限?

需要已认证的公众号(订阅号或服务号),在微信公众平台 → 开发 → 基本配置获取 AppID 和 AppSecret。

Q: 浏览器自动登录支持哪些平台?

目前支持知乎、掘金、CSDN、小红书、微博、B站等 20+ 平台,更多平台持续添加中。

Q: 多平台发布失败会怎样?

已发布成功的平台不受影响,失败平台返回具体错误信息,支持重试。

Q: 可以只发布到草稿箱吗?

是的,所有平台默认发布到草稿箱,需手动在各平台确认发布。


许可证

Apache-2.0 License