Skip to content

Commit 5272c47

Browse files
committed
feat: 与MCP共用的逻辑下沉到wenyan-core
1 parent 2571e28 commit 5272c47

File tree

14 files changed

+113
-640
lines changed

14 files changed

+113
-640
lines changed

README.md

Lines changed: 54 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
- [跨平台桌面版](https://github.com/caol64/wenyan-pc) - Windows/Linux
3030
- 👉[CLI 版本](https://github.com/caol64/wenyan-cli) - 本项目
3131
- [MCP 版本](https://github.com/caol64/wenyan-mcp) - AI 自动发文
32-
- [UI 库](https://github.com/caol64/wenyan-ui) - 桌面应用和 Web App 共用的 UI 层封装
33-
- [核心库](https://github.com/caol64/wenyan-core) - 嵌入 Node / Web 项目
3432

3533
## 特性
3634

@@ -39,81 +37,18 @@
3937
- 支持远程 Server 发布(绕过 IP 白名单限制)
4038
- 内置多套精美排版主题
4139
- 支持自定义主题
42-
- 支持 Docker 和 npm
4340
- 可作为 CI/CD 自动发文工具
4441
- 可集成 AI Agent 自动发布
4542

46-
## 本地模式和远程客户端模式
47-
48-
文颜 CLI 支持两种运行模式:**本地模式(Local Mode)****远程客户端模式(Client–Server Mode)**。两种模式运行效果完全一致,你可以根据运行环境和网络条件选择最合适的方式。
49-
50-
### 本地模式(Local Mode)
51-
52-
在本地模式下,CLI 直接调用微信公众号 API 完成图片上传和草稿发布。
53-
54-
```mermaid
55-
flowchart LR
56-
CLI[Wenyan CLI] --> Wechat[公众号 API]
57-
```
58-
59-
**优点:**
60-
61-
* 无需额外服务器
62-
* 架构简单,部署成本低
63-
* 适合个人开发者和本地使用
64-
65-
**限制:**
66-
67-
> ⚠️ 微信公众号 API 要求调用方 IP 必须在白名单内。如果没有固定 IP,需要频繁添加白名单。
68-
69-
### 远程客户端模式(Client–Server Mode)
70-
71-
在此模式下,CLI 作为客户端,将发布请求发送到部署在云服务器上的 Wenyan Server,由 Server 完成微信公众号 API 调用。
72-
73-
```mermaid
74-
flowchart LR
75-
76-
Client[Wenyan CLI Client]
77-
Server[Wenyan Server]
78-
Wechat[公众号 API]
79-
80-
Client -->|Markdown + Images| Server
81-
Server -->|Upload Media| Wechat
82-
Server -->|Create Draft| Wechat
83-
Server -->|Result| Client
84-
```
85-
86-
**优点:**
87-
88-
* 无需本地固定 IP
89-
* 完美绕过微信 IP 白名单限制
90-
* 支持动态 IP 环境
91-
* 支持团队协作
92-
* 支持 CI/CD 自动发布
93-
* 支持 AI Agent 自动发布
94-
95-
### Server 模式部署
96-
97-
[文档](docs/server.md)
98-
99-
## 安装说明
100-
101-
### npm 安装(推荐)
43+
## 快速开始
10244

10345
```bash
46+
# 安装
10447
npm install -g @wenyan-md/cli
48+
# 发布文章到公众号
49+
wenyan publish -f article.md
10550
```
10651

107-
运行:
108-
109-
```bash
110-
wenyan --help
111-
```
112-
113-
### docker 安装
114-
115-
[文档](docs/docker.md)
116-
11752
## 命令概览
11853

11954
```bash
@@ -127,32 +62,39 @@ wenyan <command> [options]
12762
| [theme](docs/theme.md) | 管理主题 |
12863
| [serve](docs/server.md) | 启动 Server |
12964

130-
## 关于图片与封面自动上传
65+
## 概念
66+
67+
### 内容输入
13168

132-
无论是本地模式还是远程客户端模式,文颜 CLI 都提供**极度智能**的图片处理机制
69+
内容输入是指如何把 Markdown 文章分发给 `wenyan-cli`,支持以下四种方式
13370

134-
- 识别并支持本地硬盘绝对路径(如:`/Users/xxx/image.jpg`
135-
- 识别并支持当前目录的相对路径(如:`./assets/image.png`
136-
- 识别并支持网络路径(如:`https://example.com/image.jpg`
71+
| 方式 | 示例 | 说明 |
72+
| ------- | --------- |--------- |
73+
| 本地路径(推荐) | `wenyan publish -f article.md` |`cli`直接读取磁盘上的文章 |
74+
| URL | `wenyan publish -f http://test.md` |`cli`直接读取网络上的文章 |
75+
| 参数 | `wenyan publish "# 文章"` |适用于快速发布短内容 |
76+
| 管道 | `cat article.md \| wenyan publish` |适用于 CI/CD,脚本批量发布 |
13777

138-
## 环境变量配置
78+
### 环境变量配置
13979

140-
在实际向微信公众号发文的环境(你的本地或部署 `serve` 的服务器)中,必须配置以下环境变量:
80+
> [!IMPORTANT]
81+
>
82+
> 请确保运行文颜的机器已配置如下环境变量,否则上传接口将调用失败。
14183
14284
- `WECHAT_APP_ID`
14385
- `WECHAT_APP_SECRET`
14486

145-
## 微信公众号 IP 白名单
87+
### 微信公众号 IP 白名单
14688

14789
> [!IMPORTANT]
14890
>
14991
> 请确保运行文颜的机器 IP 已加入微信公众号后台的 IP 白名单,否则上传接口将调用失败。
15092
15193
配置说明文档:[https://yuzhi.tech/docs/wenyan/upload](https://yuzhi.tech/docs/wenyan/upload)
15294

153-
## Markdown Frontmatter 说明(必读)
95+
### 文章格式
15496

155-
为了正确上传文章,每篇 Markdown 顶部需要包含 frontmatter:
97+
为了正确上传文章,每篇 Markdown 顶部需要包含一段 `frontmatter`
15698

15799
```md
158100
---
@@ -172,23 +114,46 @@ source_url: http://
172114
- `author` 文章作者
173115
- `source_url` 原文地址
174116

175-
## 示例文章格式
117+
**[示例文章](tests/publish.md)**
176118

177-
```md
178-
---
179-
title: 在本地跑一个大语言模型(2) - 给模型提供外部知识库
180-
cover: /Users/lei/Downloads/result_image.jpg
181-
---
119+
### 文内图片和文章封面
120+
121+
把文章发布到公众号之前,文颜会按照微信要求自动处理文章内的所有图片,将其上传到公众号素材库。目前文颜对于以下两种图片都能很好的支持:
122+
123+
- 本地硬盘绝对路径(如:`/Users/xxx/image.jpg`
124+
- 网络路径(如:`https://example.com/image.jpg`
125+
126+
仅当“内容输入”方式为“本地路径”时,以下路径也能完美支持:
182127

183-
[上一篇文章](https://babyno.top/posts/2024/02/running-a-large-language-model-locally/)中,我们展示了如何在本地运行大型语言模型。本篇将介绍如何让模型从外部知识库中检索定制数据,提升答题准确率,让它看起来更“智能”。
128+
- 当前文章的相对路径(如:`./assets/image.png`
184129

185-
## 准备模型
130+
## Server 模式
186131

187-
访问 `Ollama` 的模型页面,搜索 `qwen`,我们使用支持中文语义的“[通义千问](https://ollama.com/library/qwen:7b)”模型进行实验
132+
相较于纯本地运行的**本地模式(Local Mode)**`wenyan-cli`还提供了 **远程客户端模式(Client–Server Mode)**。两种模式运行效果完全一致,你可以根据运行环境和网络条件选择最合适的方式
188133

189-
![](https://mmbiz.qpic.cn/mmbiz_jpg/Jsq9IicjScDVUjkPc6O22ZMvmaZUzof5bLDjMyLg2HeAXd0icTvlqtL7oiarSlOicTtiaiacIxpVOV1EeMKl96PhRPPw/640?wx_fmt=jpeg)
134+
在本地模式下,CLI 直接调用微信公众号 API 完成图片上传和草稿发布。
135+
136+
```mermaid
137+
flowchart LR
138+
CLI[Wenyan CLI] --> Wechat[公众号 API]
190139
```
191140

141+
在远程客户端模式下,CLI 作为客户端,将发布请求发送到部署在云服务器上的 Wenyan Server,由 Server 完成微信公众号 API 调用。
142+
143+
```mermaid
144+
flowchart LR
145+
CLI[Wenyan CLI] --> Server[Wenyan Server] --> Wechat[公众号 API]
146+
```
147+
148+
**适用于:**
149+
150+
* 无本地固定 IP,需频繁添加IP 白名单的用户
151+
* 需团队协作的用户
152+
* 支持 CI/CD 自动发布
153+
* 支持 AI Agent 自动发布
154+
155+
**[Server 模式部署](docs/server.md)**
156+
192157
## 赞助
193158

194159
如果你觉得文颜对你有帮助,可以给我家猫咪买点罐头 ❤️

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wenyan-md/cli",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A CLI tool for Wenyan markdown rendering & publishing",
55
"author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
66
"license": "Apache-2.0",
@@ -22,12 +22,6 @@
2222
"files": [
2323
"dist"
2424
],
25-
"exports": {
26-
".": {
27-
"import": "./dist/index.js",
28-
"types": "./dist/types/index.d.ts"
29-
}
30-
},
3125
"homepage": "https://github.com/caol64/wenyan-cli#readme",
3226
"repository": {
3327
"type": "git",
@@ -50,7 +44,7 @@
5044
},
5145
"packageManager": "pnpm@10.7.1",
5246
"dependencies": {
53-
"@wenyan-md/core": "^2.0.7",
47+
"@wenyan-md/core": "^2.0.8",
5448
"commander": "^14.0.0",
5549
"express": "^5.2.1",
5650
"form-data-encoder": "^4.1.0",
@@ -59,7 +53,6 @@
5953
"multer": "^2.1.0"
6054
},
6155
"devDependencies": {
62-
"@types/jsdom": "^27.0.0",
6356
"@types/express": "^5.0.6",
6457
"@types/multer": "^2.0.0",
6558
"@types/node": "^24.3.0",

pnpm-lock.yaml

Lines changed: 5 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)