ns-rss-spider 0.0.23 → 0.0.24

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/dist/cjs/parse.js CHANGED
@@ -57,24 +57,27 @@ async function parseRss(name, feed, server) {
57
57
  });
58
58
  console.log("after num", result.items.length);
59
59
  }
60
+ if (!result.items.length) {
61
+ return {
62
+ contents: []
63
+ };
64
+ }
60
65
  const contents = [];
61
66
  const strategy = import_strategy.strategies[name];
62
- if (result.items.length) {
63
- result.items.forEach((item) => {
64
- if (!item.guid) {
65
- item.guid = item.link;
66
- }
67
- });
68
- for (let item of result.items) {
69
- console.log(import_zx.chalk.green(`正在解析文章 【${item.title}】`));
70
- if (!item.guid) {
71
- console.log(JSON.stringify(item));
72
- throw Error(`item has no guid`);
73
- }
74
- const content = await (0, import_parseContent.parseContent)(item, strategy).catch((e) => console.error(import_zx.chalk.red("文章解析失败"), e));
75
- if (content) {
76
- contents.push(content);
77
- }
67
+ result.items.forEach((item) => {
68
+ if (!item.guid) {
69
+ item.guid = item.link;
70
+ }
71
+ });
72
+ for (let item of result.items) {
73
+ console.log(import_zx.chalk.green(`正在解析文章 【${item.title}】`));
74
+ if (!item.guid) {
75
+ console.log(JSON.stringify(item));
76
+ throw Error(`item has no guid`);
77
+ }
78
+ const content = await (0, import_parseContent.parseContent)(item, strategy).catch((e) => console.error(import_zx.chalk.red("文章解析失败"), e));
79
+ if (content) {
80
+ contents.push(content);
78
81
  }
79
82
  }
80
83
  let thumbs;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/parsers/ithome.ts
@@ -23,6 +33,9 @@ __export(ithome_exports, {
23
33
  });
24
34
  module.exports = __toCommonJS(ithome_exports);
25
35
  var import_utils = require("../parseContent/utils");
36
+ var import_axios = __toESM(require("axios"));
37
+ var import_zx = require("zx");
38
+ var import_cheerio = require("cheerio");
26
39
  var ithome = {
27
40
  parse: true,
28
41
  fetcher: "http",
@@ -44,7 +57,43 @@ var ithome = {
44
57
  return $(el);
45
58
  },
46
59
  getExtraItems: async ($, rich, item) => {
47
- return {};
60
+ const source = $("#source_baidu a").text();
61
+ return {
62
+ source
63
+ };
64
+ },
65
+ getThumbs: async (articles) => {
66
+ const res = await import_axios.default.get("https://m.ithome.com/", {
67
+ responseType: "text"
68
+ }).catch((e) => {
69
+ console.error(import_zx.chalk.red("获取 https://m.ithome.com/ 错误"), e);
70
+ });
71
+ if (!res)
72
+ return void 0;
73
+ const html = res.data;
74
+ const $ = (0, import_cheerio.load)(html, null, false);
75
+ const kv = {};
76
+ $(".content > .one-img-plc > a").each((_, $a) => {
77
+ var _a, _b;
78
+ const thumb = $($a).find(".plc-image img").attr("data-original");
79
+ if (!thumb) {
80
+ return;
81
+ }
82
+ const href = $($a).attr("href") || "";
83
+ const reg = /([\d]+).htm/;
84
+ const articleId = (_a = reg.exec(href)) == null ? void 0 : _a[1];
85
+ const guid = (_b = articles.find((a) => {
86
+ const r = /([\d]+)\/([\d]+).htm/.exec(a.guid);
87
+ if (r && r[1] && r[2]) {
88
+ return `${r[1]}${r[2]}` === articleId;
89
+ }
90
+ return false;
91
+ })) == null ? void 0 : _b.guid;
92
+ if (guid && thumb) {
93
+ kv[guid] = thumb;
94
+ }
95
+ });
96
+ return kv;
48
97
  }
49
98
  };
50
99
  // Annotate the CommonJS export names for ESM import in node:
@@ -12,14 +12,14 @@ export declare function uploadContent({ app, getUploadApi, items, }: {
12
12
  items: Article[];
13
13
  } & ServerInfo): Promise<Article[] | {
14
14
  storePath: any;
15
- type: "simple" | "rich";
15
+ source?: string | undefined;
16
+ type: "rich" | "simple";
16
17
  guid: string;
17
18
  title: string;
18
19
  link: string;
19
20
  description: string;
20
21
  pubDate: Date;
21
22
  author?: string | undefined;
22
- source?: string | undefined;
23
23
  categories?: string | undefined;
24
24
  thumb?: string | undefined;
25
25
  }[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ns-rss-spider",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "build": "father build",
11
11
  "build:deps": "father prebundle",
12
12
  "check": "father doctor",
13
- "sync": "echo '去更新 registry 版本: https://www.npmmirror.com/sync/ns-rss-spider'",
13
+ "sync": "cnpm sync ns-rss-spider",
14
14
  "pub": "npm run check && npm version patch && npm run build && npm publish --registry=https://registry.npmjs.org && git push origin master --tags && npm run sync"
15
15
  },
16
16
  "bin": {
@@ -29,6 +29,7 @@
29
29
  "devDependencies": {
30
30
  "@types/lodash": "^4.14.202",
31
31
  "@types/probe-image-size": "^7.2.4",
32
+ "cnpm": "^9.4.0",
32
33
  "father": "^4.4.0",
33
34
  "vitest": "^1.2.2"
34
35
  },