@lyhue1991/wxgzh 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,32 +12,40 @@
12
12
  - 支持主题样式、自定义 CSS、自动摘要、封面图生成。
13
13
  - 也支持分步执行,便于你单独检查 HTML、封面或发布结果。
14
14
 
15
- 默认一键流程:
15
+ **操作方法**
16
+
17
+ * step1: 一键安装(要求:Node.js >= 18)
16
18
 
17
19
  ```bash
18
- wxgzh article.md
20
+ npm install -g @lyhue1991/wxgzh
21
+ ```
22
+ 安装完成后可直接使用 `wxgzh` 命令。
23
+
24
+
25
+ * step2: 一键配置 (提前准备好微信公众号AppID和 AppSecret , 并配置好IP白名单)
26
+
27
+ ```bash
28
+ wxgzh config --appid 你的AppID --appsecret 你的AppSecret
29
+
30
+ ```
31
+
32
+ * step3: 一键投稿 (将本地markdown文章直接投递到公众号草稿箱, 人工确认后即可发布)
33
+
34
+ ```bash
35
+ wxgzh article.md --author 文章作者姓名
19
36
  ```
20
37
 
21
38
  这条命令会自动执行:
22
39
 
23
40
  1. 读取 `article.md`
24
41
  2. 转换成公众号可用 HTML
25
- 3. 上传正文中的本地图片到微信
42
+ 3. 上传正文中的本地图片和非微信图床图片到微信公众号图床
26
43
  4. 自动生成封面图(如果你没有提供)
27
44
  5. 提交到微信公众号草稿箱
28
45
 
29
- ## 安装
30
-
31
- 要求:Node.js >= 18
32
46
 
33
- ```bash
34
- npm install
35
- npm run build
36
- ```
37
47
 
38
- 如果你希望全局使用命令,也可以在发布或本地链接后通过 `wxgzh` 调用。
39
-
40
- ## 二、基本配置
48
+ ## 二、配置说明
41
49
 
42
50
  ### 1. 如何获取公众号 `appid` 和 `appsecret`
43
51
 
@@ -100,8 +108,6 @@ wxgzh config --list-themes
100
108
  当前内置主题来自 `styles/` 目录,例如:`default`、`blue`、`green`、`red`、`yellow`、`brown`、`black`、`orange`。
101
109
 
102
110
 
103
-
104
-
105
111
  ## 三、快速流程
106
112
 
107
113
  最常见用法:
@@ -375,7 +381,10 @@ enableComment: true
375
381
 
376
382
  命令行参数优先级高于 Front Matter,Front Matter 又高于默认配置。
377
383
 
378
- ## 支持的 Markdown 内容
384
+
385
+ ## 六,备忘清单
386
+
387
+ ### 1. 支持的 Markdown 内容
379
388
 
380
389
  本项目当前重点支持这些常见内容:
381
390
 
@@ -387,9 +396,10 @@ enableComment: true
387
396
  - 表格
388
397
  - 数学公式(行内与块级)
389
398
 
390
- ## 常用命令速查
399
+ ### 2. 常用命令速查
391
400
 
392
401
  ```bash
402
+ wxgzh --help
393
403
  wxgzh article.md
394
404
  wxgzh config --list
395
405
  wxgzh config --list-themes
@@ -399,34 +409,4 @@ wxgzh cover --title "我的文章" --to .wxgzh/cover.jpg
399
409
  wxgzh publish --article .wxgzh/article.html --cover .wxgzh/cover.jpg
400
410
  ```
401
411
 
402
- ## 开发与构建
403
-
404
- 安装依赖:
405
-
406
- ```bash
407
- npm install
408
- ```
409
-
410
- 类型检查:
411
-
412
- ```bash
413
- npm run typecheck
414
- ```
415
-
416
- 构建:
417
-
418
- ```bash
419
- npm run build
420
- ```
421
-
422
- 查看帮助:
423
-
424
- ```bash
425
- node dist/cli/index.js --help
426
- ```
427
-
428
- ## 说明
429
412
 
430
- - 配置文件保存在用户目录下,不会写进项目源码目录。
431
- - `dist/` 是编译输出目录,日常修改应以 `src/` 为准。
432
- - 如果一键发布失败,建议改用“分步流程”逐步检查 `HTML`、图片上传和封面图。
@@ -41,9 +41,9 @@ exports.extractPublishableContent = extractPublishableContent;
41
41
  exports.readHtmlMetadata = readHtmlMetadata;
42
42
  const promises_1 = require("node:fs/promises");
43
43
  const node_path_1 = __importDefault(require("node:path"));
44
+ const css_inline_1 = require("@css-inline/css-inline");
44
45
  const cheerio = __importStar(require("cheerio"));
45
46
  const highlight_js_1 = __importDefault(require("highlight.js"));
46
- const juice_1 = __importDefault(require("juice"));
47
47
  const markdown_it_1 = __importDefault(require("markdown-it"));
48
48
  const markdown_it_mathjax3_1 = __importDefault(require("markdown-it-mathjax3"));
49
49
  const themes_1 = require("./themes");
@@ -178,6 +178,35 @@ q table:last-child {
178
178
  margin-bottom: 0 !important;
179
179
  }
180
180
  `;
181
+ const WECHAT_LAYOUT_INLINE_CSS = `
182
+ p,
183
+ h1,
184
+ h2,
185
+ h3,
186
+ h4,
187
+ h5,
188
+ h6,
189
+ ul,
190
+ ol,
191
+ dl,
192
+ blockquote,
193
+ q,
194
+ pre,
195
+ hr,
196
+ section.img-wrapper,
197
+ section.tbl-wrapper,
198
+ section.math-block {
199
+ margin-left: 0 !important;
200
+ margin-right: 0 !important;
201
+ }
202
+
203
+ section.img-wrapper,
204
+ section.tbl-wrapper,
205
+ section.math-block {
206
+ width: 100% !important;
207
+ box-sizing: border-box !important;
208
+ }
209
+ `;
181
210
  const WECHAT_TABLE_INLINE_CSS = `
182
211
  section.tbl-wrapper {
183
212
  margin: 1.4em 3% !important;
@@ -615,13 +644,11 @@ async function renderMarkdownToHtml(body, metadata) {
615
644
  const customCss = await loadCustomCss();
616
645
  const articleHtml = $('article').html() ?? '';
617
646
  const baseHtml = createDocumentHtml(articleHtml, metadata);
618
- const inlinedHtml = juice_1.default.inlineContent(baseHtml, `${themeCss}\n${HIGHLIGHT_INLINE_CSS}\n${WECHAT_BLOCKQUOTE_INLINE_CSS}\n${WECHAT_TABLE_INLINE_CSS}\n${WECHAT_MATH_INLINE_CSS}\n${customCss}`, {
619
- removeStyleTags: true,
620
- preserveMediaQueries: true,
621
- preserveFontFaces: true,
647
+ const inlinedHtml = (0, css_inline_1.inline)(baseHtml, {
648
+ extraCss: `${themeCss}\n${HIGHLIGHT_INLINE_CSS}\n${WECHAT_BLOCKQUOTE_INLINE_CSS}\n${WECHAT_TABLE_INLINE_CSS}\n${WECHAT_MATH_INLINE_CSS}\n${WECHAT_LAYOUT_INLINE_CSS}\n${customCss}`,
649
+ keepAtRules: true,
622
650
  applyWidthAttributes: false,
623
- applyHeightAttributes: false,
624
- applyAttributesTableElements: true
651
+ applyHeightAttributes: false
625
652
  });
626
653
  return cleanInlinedHtml(inlinedHtml);
627
654
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyhue1991/wxgzh",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Markdown to WeChat Official Account draft CLI",
5
5
  "license": "MIT",
6
6
  "main": "dist/cli/index.js",
@@ -26,14 +26,14 @@
26
26
  "node": ">=18"
27
27
  },
28
28
  "dependencies": {
29
+ "@css-inline/css-inline": "^0.20.0",
29
30
  "axios": "^1.8.4",
30
- "cheerio": "^1.0.0",
31
+ "cheerio": "1.0.0-rc.12",
31
32
  "commander": "^14.0.1",
32
33
  "dotenv": "^16.4.7",
33
34
  "form-data": "^4.0.2",
34
35
  "gray-matter": "^4.0.3",
35
36
  "highlight.js": "^11.11.1",
36
- "juice": "^11.1.1",
37
37
  "markdown-it": "^14.1.0",
38
38
  "markdown-it-mathjax3": "^5.2.0",
39
39
  "mathjax": "^4.1.1",