ns-rss-spider 0.0.24 → 0.0.26

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
@@ -49,6 +49,7 @@ async function parseRss(name, feed, server) {
49
49
  if (!result.items.length) {
50
50
  throw Error("rss no conent");
51
51
  }
52
+ const originRss = [...result.items];
52
53
  if (server == null ? void 0 : server.latest) {
53
54
  const d = new Date(server.latest.pubDate);
54
55
  console.log("server lastest", d, "before num", result.items.length);
@@ -57,33 +58,30 @@ async function parseRss(name, feed, server) {
57
58
  });
58
59
  console.log("after num", result.items.length);
59
60
  }
60
- if (!result.items.length) {
61
- return {
62
- contents: []
63
- };
64
- }
65
61
  const contents = [];
66
62
  const strategy = import_strategy.strategies[name];
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);
63
+ if (result.items.length) {
64
+ result.items.forEach((item) => {
65
+ if (!item.guid) {
66
+ item.guid = item.link;
67
+ }
68
+ });
69
+ for (let item of result.items) {
70
+ console.log(import_zx.chalk.green(`正在解析文章 【${item.title}】`));
71
+ if (!item.guid) {
72
+ console.log(JSON.stringify(item));
73
+ throw Error(`item has no guid`);
74
+ }
75
+ const content = await (0, import_parseContent.parseContent)(item, strategy).catch((e) => console.error(import_zx.chalk.red("文章解析失败"), e));
76
+ if (content) {
77
+ contents.push(content);
78
+ }
81
79
  }
82
80
  }
83
81
  let thumbs;
84
82
  if (strategy == null ? void 0 : strategy.getThumbs) {
85
83
  console.log(import_zx.chalk.green(`正在获取缩略图数据`));
86
- const thumbKv = await (strategy == null ? void 0 : strategy.getThumbs(contents));
84
+ const thumbKv = await (strategy == null ? void 0 : strategy.getThumbs(originRss));
87
85
  if (thumbKv && Object.keys(thumbKv).length) {
88
86
  console.log(import_zx.chalk.green(`正在更新缩略图`));
89
87
  thumbs = thumbKv;
@@ -57,7 +57,7 @@ var cnbeta = {
57
57
  };
58
58
  },
59
59
  ignoreProbeImage: true,
60
- getThumbs: async (articles) => {
60
+ getThumbs: async (items) => {
61
61
  const res = await import_axios.default.get("https://m.cnbeta.com.tw/", {
62
62
  responseType: "text"
63
63
  }).catch((e) => {
@@ -74,7 +74,7 @@ var cnbeta = {
74
74
  const href = $($a).attr("href") || "";
75
75
  const reg = /([\d]+).htm/;
76
76
  const articleId = (_a = reg.exec(href)) == null ? void 0 : _a[1];
77
- const guid = (_b = articles.find((a) => a.guid.includes(`/${articleId}.htm`))) == null ? void 0 : _b.guid;
77
+ const guid = (_b = items.find((a) => (a.guid || a.link || "").includes(`/${articleId}.htm`))) == null ? void 0 : _b.guid;
78
78
  if (guid && thumb) {
79
79
  kv[guid] = thumb;
80
80
  }
@@ -83,7 +83,7 @@ var ithome = {
83
83
  const reg = /([\d]+).htm/;
84
84
  const articleId = (_a = reg.exec(href)) == null ? void 0 : _a[1];
85
85
  const guid = (_b = articles.find((a) => {
86
- const r = /([\d]+)\/([\d]+).htm/.exec(a.guid);
86
+ const r = /([\d]+)\/([\d]+).htm/.exec(a.guid || a.link || "");
87
87
  if (r && r[1] && r[2]) {
88
88
  return `${r[1]}${r[2]}` === articleId;
89
89
  }
@@ -11,7 +11,7 @@ export interface ParseStrategy {
11
11
  getContentFromHtml?: ($: CheerioAPI, node: Cheerio<AnyNode>) => string;
12
12
  getExtraItems?: ($: CheerioAPI, current: RichArticle, item: Item) => Promise<Record<string, any>>;
13
13
  ignoreProbeImage?: boolean;
14
- getThumbs?: (articles: Article[]) => Promise<Record<string, string> | undefined>;
14
+ getThumbs?: (items: Item[]) => Promise<Record<string, string> | undefined>;
15
15
  }
16
16
  export interface SimpleArticle {
17
17
  type: 'simple';
@@ -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
- source?: string | undefined;
16
- type: "rich" | "simple";
15
+ type: "simple" | "rich";
17
16
  guid: string;
18
17
  title: string;
19
18
  link: string;
20
19
  description: string;
21
20
  pubDate: Date;
22
21
  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.24",
3
+ "version": "0.0.26",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",