Skip to content

feat: CLI support type:image for newspic publishing#32

Closed
turinglambdaai wants to merge 0 commit into
caol64:mainfrom
turinglambdaai:feat/newspic-support
Closed

feat: CLI support type:image for newspic publishing#32
turinglambdaai wants to merge 0 commit into
caol64:mainfrom
turinglambdaai:feat/newspic-support

Conversation

@turinglambdaai

Copy link
Copy Markdown
Contributor

Summary

  • CLI wenyan publish now detects type: image in frontmatter, automatically extracts image references from the body, injects image_list, and routes to the newspic (小绿书) publishing path
  • Added transformImageTypeContent utility to handle the type: imageimage_list transformation
  • Upgraded @wenyan-md/core to 3.0.6 which provides publishImageTextToWechatDraft

Changes

  • src/utils.ts: Added transformImageTypeContent() — parses frontmatter for type: image, extracts ![](path) and ![[path]] images from body, injects image_list into frontmatter, removes image references from body text
  • src/cli.ts: Wrapped getInputContent to apply the transform before passing to core's rendering pipeline. Works for both server mode (--server) and local mode
  • package.json: Upgraded @wenyan-md/core from ^3.0.5 to ^3.0.6

How it works

wenyan publish -f article.md
  → getInputContent reads file
  → transformImageTypeContent detects type: image
  → extracts images from body → injects image_list into frontmatter
  → core's handleFrontMatter picks up image_list
  → core routes to publishImageTextToWechatDraft (local) or uploads image_list (server)

No changes needed to core module — it already handles image_list natively.

Test plan

  • Build passes (pnpm build)
  • E2E: type: image article published successfully to WeChat draft via server mode
  • Regression: normal article (no type: image) still publishes correctly
  • Unit tests for transformImageTypeContent (existing test infra has module resolution issues on Windows/pnpm)

@caol64

caol64 commented Apr 22, 2026

Copy link
Copy Markdown
Owner

这个功能是什么意思啊?

@turinglambdaai

Copy link
Copy Markdown
Contributor Author

感谢 review!这个 PR 补全了小绿书(贴图)发布在 CLI 端的缺失环节。

之前 serve 端已经支持了 image_list 触发小绿书发布路径,但 CLI 的 wenyan publish 命令无法感知文章类型——用户只能手动构造 API 请求才能触发小绿书,无法像普通文章那样直接用命令行发布。

这个 PR 的改动:

  1. CLI 自动感知 type: image:当 Markdown frontmatter 中有 type: image 时,CLI 自动从正文中提取图片路径,注入 image_list 字段到 frontmatter,然后传给 core 的现有发布流程
  2. 两种模式统一入口:普通文章和小绿书都用 wenyan publish -f article.md,CLI 根据 type 自动分流,用户不需要关心底层差异
  3. 升级 core 到 3.0.6:获取 publishImageTextToWechatDraft 函数

改动很小(核心逻辑在 src/utils.tstransformImageTypeContent 函数,约 40 行),不需要改 core 模块——core 已经有完整的 image_list 处理能力,只是 CLI 侧缺了一个触发入口。

@turinglambdaai

Copy link
Copy Markdown
Contributor Author

补充一下设计思路:

为什么用 type 字段而不是单独的命令(如 publish-image):

微信公众号后台本身就把内容分为「文章」「贴图」「视频」「音频」四种类型,type 字段直接对应这个分类体系。未来如果要支持视频或音频,只需要新增 type: video / type: audio 的分支处理,复用同一个字段,不需要为每种类型加一个新命令。

为什么自动从正文提取图片,而不是让用户手动填写 image_list

图片已经写在正文里了(![](path)![[path]]),让用户在 frontmatter 里再列一遍是重复操作。CLI 检测到 type: image 后自动提取,用户只需要写一个字段就够了。

流程:

  1. 用户在 frontmatter 写 type: image
  2. CLI 读到后,从正文提取所有 ![]() 图片路径,注入 image_list 到 frontmatter
  3. 删掉正文中的图片引用(小绿书的图片在图片列表展示,不应重复出现在正文中)
  4. 交给 core 现有的 image_list 处理流程

这样用户侧的改动最小——加一个字段,图片照常写在正文里就行。

@caol64

caol64 commented Apr 22, 2026

Copy link
Copy Markdown
Owner

目前可以通过frontmatter是否有image_list字段来区分是小绿书还是图文,不需要单独添加type字段也能区分。

你可能是想把正常写的图文也能当小绿书发布,这样就有必要添加type字段了。

@turinglambdaai

turinglambdaai commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

对,你说得没错。core 本身已经通过 image_list 有无来区分,type 不是必须的。

我加 type 的意图正是你说的第二点:让正常写的图文文章也能当小绿书发布。实际场景是这样的:

用户在 Obsidian 里写了一篇带图片的笔记,正文里自然地写了 ![](photo.jpg)。如果要用小绿书发布,用户有两种方式:

  1. 手动方式:在 frontmatter 里手动加 image_list 字段,把图片路径再列一遍
  2. type: image:只加一个字段,CLI 自动从正文提取图片,注入 image_list

第二种方式对用户更友好,不用重复填写图片路径。

@turinglambdaai

Copy link
Copy Markdown
Contributor Author

根据我们在 caol64/wenyan-core#17 的讨论,已将 type: imageimage_list 的转换逻辑下沉到 core 模块,见 caol64/wenyan-core#20

core 合并后,CLI 无需任何代码改动——handleFrontMatter 会自动处理 type: image,现有的 ^3.0.6 版本约束会自动使用包含此功能的新版本。

本 PR 可以关闭。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants