yz-yuki-plugin 1.0.3-rc.1 → 1.0.3-rc.3

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
@@ -15,11 +15,22 @@
15
15
 
16
16
  ##### ```Yunzai-Next:```
17
17
 
18
- 1. yunzai-next npm包 方式 安装插件:
18
+ 1. 方式1: yunzai-next npm包 安装插件:
19
19
  >```
20
20
  > yarn add yz-yuki-plugin -W
21
21
  >```
22
- 接着修改 `yunzaijs/yunzai.config.js`:
22
+ 接着修改 `yunzaijs/yunzai.config.js`,按版本选择修改方式:
23
+
24
+ Yunzai-Next v4.1.28+及以上版本:
25
+ ```js
26
+ import { defineConfig } from 'yunzai'
27
+ export default defineConfig({
28
+ applications: ['yz-system', 'yz-yuki-plugin'], //该行添加 'yz-yuki-plugin'
29
+ middlewares: ['yz-mw-runtime', 'yunzai-mys/mw']
30
+ })
31
+ ```
32
+
33
+ 旧版本:
23
34
  ```js
24
35
  import yuki from 'yz-yuki-plugin' //新增该行
25
36
  export default defineConfig({
@@ -28,7 +39,7 @@ export default defineConfig({
28
39
  })
29
40
  ```
30
41
 
31
- 2. 旧的方式安装:
42
+ 2. 方式2(V3的方式):
32
43
  >gitee仓库:
33
44
  >```
34
45
  >git clone --branch main https://gitee.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
@@ -52,6 +63,8 @@ export default defineConfig({
52
63
 
53
64
  #### 2. 安装依赖
54
65
  * Yunzai-Next:
66
+
67
+ 方式2(V3的方式)安装则需要执行:
55
68
  ```
56
69
  yarn install
57
70
  ```
@@ -55,6 +55,12 @@ class BiliQuery {
55
55
  pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; });
56
56
  formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
57
57
  }
58
+ else if (majorType === "MAJOR_TYPE_DRAW") {
59
+ desc = data?.modules?.module_dynamic?.desc;
60
+ pics = data?.modules?.module_dynamic?.major?.draw?.items;
61
+ pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; });
62
+ formatData.data.content = this.parseRichTextNodes(desc?.rich_text_nodes || desc?.text) || "";
63
+ }
58
64
  else {
59
65
  desc = data?.modules?.module_dynamic?.desc;
60
66
  pics = data?.modules?.module_dynamic?.major?.draw?.items;
@@ -89,6 +95,13 @@ class BiliQuery {
89
95
  formatData.data.pics = pics;
90
96
  }
91
97
  }
98
+ else if (majorType === "MAJOR_TYPE_ARTICLE") {
99
+ desc = data?.modules?.module_dynamic?.major?.article || {};
100
+ pics = desc?.covers;
101
+ pics = pics.map((item) => { return { url: item }; }) || [];
102
+ formatData.data.title = desc?.title;
103
+ formatData.data.content = this.parseRichTextNodes(desc?.desc);
104
+ }
92
105
  else {
93
106
  desc = data?.modules?.module_dynamic?.major?.article || {};
94
107
  if (desc.covers && desc.covers.length) {
@@ -139,6 +152,7 @@ class BiliQuery {
139
152
  ;
140
153
  static parseRichTextNodes = (nodes) => {
141
154
  if (typeof nodes === 'string') {
155
+ nodes = nodes.replace(/\t/g, ' ');
142
156
  return nodes.replace(/\n/g, '<br>');
143
157
  }
144
158
  else if (Array.isArray(nodes)) {
@@ -194,7 +208,7 @@ class BiliQuery {
194
208
  }
195
209
  }
196
210
  static praseFullArticleContent(content) {
197
- content = content.replace(/\n/g, '<br>');
211
+ content = String(content).replace(/\n/g, '<br>');
198
212
  const imgTagRegex = /<img[^>]*data-src="([^"]*)"[^>]*>/g;
199
213
  content = content.replace(imgTagRegex, (match, p1) => {
200
214
  const newSrc = this.formatUrl(p1);
@@ -263,6 +277,12 @@ class BiliQuery {
263
277
  });
264
278
  content = desc?.summary?.text || "";
265
279
  }
280
+ else if (majorType === "MAJOR_TYPE_DRAW") {
281
+ desc = data?.modules?.module_dynamic?.desc;
282
+ pics = data?.modules?.module_dynamic?.major?.draw?.items;
283
+ pics = pics.map((item) => { return item?.src; });
284
+ content = desc?.text || "";
285
+ }
266
286
  else {
267
287
  desc = data?.modules?.module_dynamic?.desc;
268
288
  pics = data?.modules?.module_dynamic?.major?.draw?.items;
@@ -298,6 +318,12 @@ class BiliQuery {
298
318
  dynamicTitle = desc?.title;
299
319
  content = desc?.summary?.text || "";
300
320
  }
321
+ else if (majorType === "MAJOR_TYPE_ARTICLE") {
322
+ desc = data?.modules?.module_dynamic?.major?.article || {};
323
+ pics = desc?.covers || [];
324
+ dynamicTitle = desc?.title;
325
+ content = desc?.desc;
326
+ }
301
327
  else {
302
328
  desc = data?.modules?.module_dynamic?.major?.article || {};
303
329
  if (desc.covers && desc.covers.length) {
@@ -23,10 +23,10 @@ class YukiPuppeteerRender extends Puppeteer {
23
23
  await page.setExtraHTTPHeaders(Options.header);
24
24
  }
25
25
  await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil: ["load", "networkidle0"] });
26
- const body = await page.$(Options?.tab ?? 'body');
27
- if (!body)
26
+ const element = await page.$(Options?.tab ?? 'body');
27
+ if (!element)
28
28
  return false;
29
- const boundingBox = await body.boundingBox();
29
+ const boundingBox = await element.boundingBox();
30
30
  const num = Options?.isSplit ? Math.ceil(boundingBox.height / pageHeight) : 1;
31
31
  pageHeight = Math.round(boundingBox.height / num);
32
32
  await page.setViewport({
@@ -71,7 +71,7 @@ class YukiPuppeteerRender extends Puppeteer {
71
71
  height: Math.min(pageHeight, boundingBox.height - pageHeight * (i - 1)),
72
72
  },
73
73
  };
74
- buff = await page.screenshot(screenshotOptions).catch(err => {
74
+ buff = await element.screenshot(screenshotOptions).catch(err => {
75
75
  logger.error('[puppeteer]', 'screenshot', err);
76
76
  return false;
77
77
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "1.0.3-rc.1",
3
+ "version": "1.0.3-rc.3",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "qrcode": "^1.5.4",
33
33
  "react": "^18.3.1",
34
34
  "react-dom": "^18.3.1",
35
- "react-puppeteer": "1.0.2",
35
+ "react-puppeteer": "1.0.3",
36
36
  "redis": "^4.7.0",
37
37
  "yaml": "^2.5.0",
38
38
  "yarn": "^1.19.1"
@@ -67,7 +67,7 @@
67
67
  "qrcode": "^1.5.4",
68
68
  "react": "^18.3.1",
69
69
  "react-dom": "^18.3.1",
70
- "react-puppeteer": "1.0.2",
70
+ "react-puppeteer": "1.0.3",
71
71
  "redis": "^4.7.0",
72
72
  "rollup": "^4.20.0",
73
73
  "rollup-plugin-auto-external": "^2.0.0",
@@ -8,6 +8,7 @@
8
8
  body {
9
9
  width: 563px !important;
10
10
  font-family: "OPSans", Arial, sans-serif;
11
+ margin: auto;
11
12
  }
12
13
 
13
14
  .container {