rsshub 1.0.0-master.e52c829 → 1.0.0-master.e555c61

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.
Files changed (87) hide show
  1. package/lib/config.js +2 -0
  2. package/lib/router.js +4 -3
  3. package/lib/routes/hopper/index.js +2 -2
  4. package/lib/utils/got.js +5 -1
  5. package/lib/utils/request-wrapper.js +53 -13
  6. package/lib/v2/2048/index.js +7 -5
  7. package/lib/v2/agefans/detail.js +20 -15
  8. package/lib/v2/agefans/radar.js +20 -17
  9. package/lib/v2/agefans/update.js +17 -8
  10. package/lib/v2/agefans/utils.js +5 -0
  11. package/lib/v2/aisixiang/column.js +22 -13
  12. package/lib/v2/aisixiang/maintainer.js +1 -0
  13. package/lib/v2/aisixiang/radar.js +6 -0
  14. package/lib/v2/aisixiang/router.js +1 -0
  15. package/lib/v2/aisixiang/thinktank.js +13 -13
  16. package/lib/v2/aisixiang/toplist.js +21 -15
  17. package/lib/v2/aisixiang/utils.js +16 -10
  18. package/lib/v2/aisixiang/zhuanti.js +45 -0
  19. package/lib/v2/apnews/topics.js +24 -29
  20. package/lib/v2/bilibili/followers.js +12 -1
  21. package/lib/v2/bilibili/followings.js +16 -1
  22. package/lib/v2/bilibili/maintainer.js +2 -2
  23. package/lib/v2/bilibili/router.js +2 -2
  24. package/lib/v2/blizzard/maintainer.js +3 -0
  25. package/lib/{routes → v2}/blizzard/news.js +14 -15
  26. package/lib/v2/blizzard/radar.js +13 -0
  27. package/lib/v2/blizzard/router.js +3 -0
  28. package/lib/v2/bloomberg/react-renderer.js +190 -0
  29. package/lib/v2/bloomberg/templates/chart_media.art +21 -0
  30. package/lib/v2/bloomberg/templates/image_figure.art +1 -1
  31. package/lib/v2/bloomberg/utils.js +41 -8
  32. package/lib/v2/cbaigui/index.js +100 -0
  33. package/lib/v2/cbaigui/maintainer.js +3 -0
  34. package/lib/v2/cbaigui/radar.js +18 -0
  35. package/lib/v2/cbaigui/router.js +3 -0
  36. package/lib/v2/cbaigui/templates/figure.art +3 -0
  37. package/lib/v2/cbaigui/utils.js +18 -0
  38. package/lib/v2/copymanga/comic.js +74 -58
  39. package/lib/v2/copymanga/templates/comic.art +1 -1
  40. package/lib/v2/dhu/maintainer.js +1 -0
  41. package/lib/v2/dhu/radar.js +6 -0
  42. package/lib/v2/dhu/router.js +1 -0
  43. package/lib/v2/dhu/yjs/news.js +47 -0
  44. package/lib/v2/gov/maintainer.js +2 -0
  45. package/lib/v2/gov/nrta/dsj.js +59 -0
  46. package/lib/v2/gov/radar.js +21 -0
  47. package/lib/v2/gov/router.js +2 -0
  48. package/lib/v2/gov/shanghai/wgj/templates/wgj.art +15 -0
  49. package/lib/v2/gov/shanghai/wgj/wgj.js +72 -0
  50. package/lib/v2/javdb/lists.js +28 -0
  51. package/lib/v2/javdb/maintainer.js +5 -4
  52. package/lib/v2/javdb/radar.js +6 -0
  53. package/lib/v2/javdb/router.js +5 -4
  54. package/lib/v2/javdb/search.js +9 -2
  55. package/lib/v2/javdb/utils.js +6 -5
  56. package/lib/v2/npr/full.js +89 -0
  57. package/lib/v2/npr/maintainer.js +3 -0
  58. package/lib/v2/npr/radar.js +11 -0
  59. package/lib/v2/npr/router.js +3 -0
  60. package/lib/v2/qidian/chapter.js +14 -18
  61. package/lib/v2/qidian/maintainer.js +2 -2
  62. package/lib/v2/sec-in/index.js +19 -0
  63. package/lib/v2/sec-in/maintainer.js +3 -0
  64. package/lib/v2/sec-in/radar.js +11 -0
  65. package/lib/v2/sec-in/router.js +3 -0
  66. package/lib/v2/sec-wiki/maintainer.js +3 -0
  67. package/lib/v2/sec-wiki/radar.js +11 -0
  68. package/lib/v2/sec-wiki/router.js +3 -0
  69. package/lib/v2/sec-wiki/weekly.js +16 -0
  70. package/lib/v2/shu/index.js +48 -0
  71. package/lib/v2/shu/jwb.js +45 -0
  72. package/lib/v2/shu/maintainer.js +4 -0
  73. package/lib/v2/shu/radar.js +21 -0
  74. package/lib/v2/shu/router.js +5 -0
  75. package/lib/v2/stheadline/std/realtime.js +1 -1
  76. package/lib/v2/twitter/utils.js +10 -4
  77. package/lib/v2/twitter/web-api/constants.js +6 -3
  78. package/lib/v2/twitter/web-api/twitter-api.js +14 -38
  79. package/lib/v2/twitter/web-api/twitter-got.js +11 -7
  80. package/lib/v2/v2rayshare/index.js +22 -0
  81. package/lib/v2/v2rayshare/maintainer.js +3 -0
  82. package/lib/v2/v2rayshare/radar.js +13 -0
  83. package/lib/v2/v2rayshare/router.js +3 -0
  84. package/lib/v2/wikinews/index.js +28 -29
  85. package/package.json +31 -25
  86. package/lib/routes/universities/shu/index.js +0 -75
  87. package/lib/routes/universities/shu/jwc.js +0 -62
package/lib/config.js CHANGED
@@ -73,6 +73,8 @@ const calculateValue = () => {
73
73
  auth: envs.PROXY_AUTH,
74
74
  url_regex: envs.PROXY_URL_REGEX || '.*',
75
75
  },
76
+ proxyStrategy: envs.PROXY_STRATEGY || 'all', // all / on_retry
77
+ reverseProxyUrl: envs.REVERSE_PROXY_URL,
76
78
  // auth
77
79
  authentication: {
78
80
  name: envs.HTTP_BASIC_AUTH_NAME || 'usernam3',
package/lib/router.js CHANGED
@@ -744,8 +744,9 @@ router.get('/zjut/:type', lazyloadRouteHandler('./routes/universities/zjut/index
744
744
  router.get('/zjut/design/:type', lazyloadRouteHandler('./routes/universities/zjut/design'));
745
745
 
746
746
  // 上海大学
747
- router.get('/shu/:type?', lazyloadRouteHandler('./routes/universities/shu/index'));
748
- router.get('/shu/jwc/:type?', lazyloadRouteHandler('./routes/universities/shu/jwc'));
747
+ // router.get('/shu/:type?', lazyloadRouteHandler('./routes/universities/shu/index'));
748
+ // router.get('/shu/jwc/:type?', lazyloadRouteHandler('./routes/universities/shu/jwc'));
749
+ // router.get('/shu/jwb/:type?', lazyloadRouteHandler('./routes/universities/shu/jwc'));
749
750
 
750
751
  // 北京科技大学天津学院
751
752
  // router.get('/ustb/tj/news/:type?', lazyloadRouteHandler('./routes/universities/ustb/tj/news'));
@@ -3408,7 +3409,7 @@ router.get('/rescuetime/release-notes/:os?', lazyloadRouteHandler('./routes/resc
3408
3409
  router.get('/totalcommander/whatsnew', lazyloadRouteHandler('./routes/totalcommander/whatsnew'));
3409
3410
 
3410
3411
  // Blizzard
3411
- router.get('/blizzard/news/:language?/:category?', lazyloadRouteHandler('./routes/blizzard/news'));
3412
+ // router.get('/blizzard/news/:language?/:category?', lazyloadRouteHandler('./routes/blizzard/news'));
3412
3413
 
3413
3414
  // DeepMind
3414
3415
  // router.get('/deepmind/blog/:category?', lazyloadRouteHandler('./routes/deepmind/blog'));
@@ -72,8 +72,8 @@ const formatDesc = (e) => {
72
72
 
73
73
  const description = `<table><tbody><tr><th align="left" style="border: 1px solid black;">From</th><th align="left" style="border: 1px solid black;">To</th><th align="left" style="border: 1px solid black;">Price</th></tr><tr><td style="border: 1px solid black;">
74
74
  ${origin}</td><td style="border: 1px solid black;">${destination}</td><td style="border: 1px solid black;">${price}</td></tr></tbody></table>${dayjs(departureDate).format('YYYY MMM DD')} &#9992; ${dayjs(returnDate).format(
75
- 'YYYY MMM DD'
76
- )}`;
75
+ 'YYYY MMM DD'
76
+ )}`;
77
77
  return {
78
78
  title,
79
79
  description,
package/lib/utils/got.js CHANGED
@@ -3,11 +3,15 @@ const config = require('@/config').value;
3
3
  const got = require('got');
4
4
 
5
5
  const custom = got.extend({
6
- retry: config.requestRetry,
6
+ retry: {
7
+ limit: config.requestRetry,
8
+ statusCodes: [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511, 521, 522, 524],
9
+ },
7
10
  hooks: {
8
11
  beforeRetry: [
9
12
  (options, err, count) => {
10
13
  logger.error(`Request ${options.url} fail, retry attempt #${count}: ${err}`);
14
+ options.retryCount = count;
11
15
  },
12
16
  ],
13
17
  afterResponse: [
@@ -20,7 +20,13 @@ if (agent) {
20
20
  const proxyRegex = new RegExp(proxyObj.url_regex);
21
21
  const protocolMatch = (protocolLike) => protocolLike && protocolLike.toLowerCase().startsWith('http');
22
22
 
23
- proxyWrapper = (url, options, urlHandler) => {
23
+ proxyWrapper = (url, options) => {
24
+ let urlHandler;
25
+ try {
26
+ urlHandler = new URL(url);
27
+ } catch (error) {
28
+ // ignore
29
+ }
24
30
  if (proxyRegex.test(url)) {
25
31
  if ((protocolMatch(options.protocol) || protocolMatch(url)) && (!urlHandler || urlHandler.host !== proxyUrlHandler.host)) {
26
32
  options.agent = agent;
@@ -32,40 +38,73 @@ if (agent) {
32
38
  }
33
39
  return false;
34
40
  };
41
+ } else if (config.reverseProxyUrl) {
42
+ proxyWrapper = (url, options) => {
43
+ const urlIn = options.url?.toString() || url;
44
+ const proxyRegex = new RegExp(proxyObj.url_regex);
45
+ if (
46
+ proxyRegex.test(urlIn) &&
47
+ !urlIn.startsWith(config.reverseProxyUrl) &&
48
+ !options.cookieJar &&
49
+ !options.headers['user-agent']?.startsWith('PixivIOSApp') &&
50
+ !options.headers['x-goog-api-client'] &&
51
+ options.headers.accept !== 'application/dns-json'
52
+ ) {
53
+ options.url = new URL(`${config.reverseProxyUrl}${encodeURIComponent(urlIn)}`);
54
+
55
+ return true;
56
+ }
57
+ return false;
58
+ };
35
59
  }
36
60
 
37
- const requestWrapper = (url, options) => {
38
- let urlHandler;
39
- try {
40
- urlHandler = new URL(url);
41
- } catch (error) {
42
- // ignore
61
+ const requestWrapper = (
62
+ url,
63
+ options = {
64
+ headers: {},
43
65
  }
66
+ ) => {
44
67
  options.headers = options.headers || {};
45
68
  const headersLowerCaseKeys = Object.keys(options.headers).map((key) => key.toLowerCase());
46
69
 
47
- proxyWrapper(url, options, urlHandler) ? logger.info(`Proxy for ${url}`) : logger.debug(`Requesting ${url}`);
70
+ let prxied = false;
71
+ if (config.proxyStrategy === 'all') {
72
+ prxied = proxyWrapper(url, options);
73
+ } else if (config.proxyStrategy === 'on_retry') {
74
+ if (options.retryCount) {
75
+ prxied = proxyWrapper(url, options);
76
+ }
77
+ }
78
+ if (prxied) {
79
+ logger.debug(`Proxy for ${url}`);
80
+ } else {
81
+ logger.debug(`Requesting ${url}`);
82
+ }
48
83
 
49
84
  // ua
50
85
  if (!headersLowerCaseKeys.includes('user-agent')) {
51
86
  options.headers['user-agent'] = config.ua;
52
87
  }
53
88
 
89
+ let urlHandler;
90
+ try {
91
+ urlHandler = new URL(options.url || url);
92
+ } catch (error) {
93
+ // ignore
94
+ }
95
+
54
96
  if (urlHandler) {
55
97
  // referer
56
98
  if (!headersLowerCaseKeys.includes('referer')) {
57
99
  options.headers.referer = urlHandler.origin;
58
100
  }
59
- // host
60
- if (!headersLowerCaseKeys.includes('host')) {
61
- options.headers.host = urlHandler.host;
62
- }
63
101
  }
64
102
  };
65
103
 
66
104
  const httpWrap = (func) => {
67
105
  const origin = func;
68
106
  return function (url, request) {
107
+ const args = Array.prototype.slice.call(arguments);
69
108
  if (typeof url === 'object') {
70
109
  if (url instanceof URL) {
71
110
  requestWrapper(url.toString(), request);
@@ -76,7 +115,8 @@ const httpWrap = (func) => {
76
115
  } else {
77
116
  requestWrapper(url, request);
78
117
  }
79
- return origin.apply(this, arguments);
118
+ args[0] = request?.url || url;
119
+ return origin.apply(this, args);
80
120
  };
81
121
  };
82
122
 
@@ -17,6 +17,7 @@ module.exports = async (ctx) => {
17
17
  });
18
18
 
19
19
  const $ = cheerio.load(response.data);
20
+ const currentHost = `https://${new URL(response.url).host}`; // redirected host
20
21
 
21
22
  $('#shortcut').remove();
22
23
  $('tr[onmouseover="this.className=\'tr3 t_two\'"]').remove();
@@ -24,19 +25,20 @@ module.exports = async (ctx) => {
24
25
  const list = $('#ajaxtable tbody .tr2')
25
26
  .last()
26
27
  .nextAll('.tr3')
27
- .map((_, item) => {
28
+ .toArray()
29
+ .map((item) => {
28
30
  item = $(item).find('.subject');
29
31
 
30
32
  return {
31
33
  title: item.text(),
32
- link: `${rootUrl}/2048/${item.attr('href')}`,
34
+ link: `${currentHost}/2048/${item.attr('href')}`,
35
+ guid: `${rootUrl}/2048/${item.attr('href')}`,
33
36
  };
34
- })
35
- .get();
37
+ });
36
38
 
37
39
  const items = await Promise.all(
38
40
  list.map((item) =>
39
- ctx.cache.tryGet(item.link, async () => {
41
+ ctx.cache.tryGet(item.guid, async () => {
40
42
  const detailResponse = await got({
41
43
  method: 'get',
42
44
  url: item.link,
@@ -1,26 +1,31 @@
1
1
  const got = require('@/utils/got');
2
2
  const cheerio = require('cheerio');
3
+ const { rootUrl } = require('./utils');
3
4
 
4
5
  module.exports = async (ctx) => {
5
- const response = await got(`https://www.agemys.cc/detail/${ctx.params.id}`);
6
+ const response = await got(`${rootUrl}/detail/${ctx.params.id}`);
6
7
  const $ = cheerio.load(response.data);
7
8
 
8
- const defaultIdx = parseInt($('#DEF_PLAYINDEX').get(0).children[0].data);
9
- const items = $('#main0 div')
10
- .filter((idx) => defaultIdx === idx)
11
- .find('a')
12
- .map((idx, item) => ({
13
- title: $(item).text(),
14
- description: $(item).text(),
15
- link: `https://www.agemys.cc${$(item).attr('href')}`,
16
- }))
17
- .get();
18
- items.reverse();
9
+ const ldJson = JSON.parse($('script[type="application/ld+json"]').text());
10
+
11
+ const items = $('.video_detail_episode')
12
+ .first()
13
+ .find('li')
14
+ .toArray()
15
+ .map((item) => {
16
+ item = $(item);
17
+ const a = item.find('a');
18
+ return {
19
+ title: a.text(),
20
+ link: a.attr('href').replace('http://', 'https://'),
21
+ };
22
+ })
23
+ .reverse();
19
24
 
20
25
  ctx.state.data = {
21
- title: `AGE动漫 - ${$('.detail_imform_name').text()}`,
22
- link: `https://www.agemys.cc/detail/${ctx.params.id}`,
23
- description: $('.detail_imform_desc_pre').text(),
26
+ title: `AGE动漫 - ${ldJson.name}`,
27
+ link: `${rootUrl}/detail/${ctx.params.id}`,
28
+ description: ldJson.description,
24
29
  item: items,
25
30
  };
26
31
  };
@@ -1,19 +1,22 @@
1
+ const ageFans = {
2
+ _name: 'AGE动漫',
3
+ '.': [
4
+ {
5
+ title: '最近更新',
6
+ docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
7
+ source: ['/update', '/'],
8
+ target: '/agefans/update',
9
+ },
10
+ {
11
+ title: '番剧详情',
12
+ docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
13
+ source: ['/detail/:id'],
14
+ target: '/agefans/detail/:id',
15
+ },
16
+ ],
17
+ };
18
+
1
19
  module.exports = {
2
- 'agemys.cc': {
3
- _name: 'AGE动漫',
4
- '.': [
5
- {
6
- title: '最近更新',
7
- docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
8
- source: ['/update', '/'],
9
- target: '/agefans/update',
10
- },
11
- {
12
- title: '番剧详情',
13
- docs: 'https://docs.rsshub.app/anime.html#age-dong-man',
14
- source: ['/detail/:id'],
15
- target: '/agefans/detail/:id',
16
- },
17
- ],
18
- },
20
+ 'agemys.cc': ageFans,
21
+ 'agemys.org': ageFans,
19
22
  };
@@ -1,23 +1,24 @@
1
1
  const got = require('@/utils/got');
2
2
  const cheerio = require('cheerio');
3
+ const { rootUrl } = require('./utils');
3
4
 
4
5
  module.exports = async (ctx) => {
5
- const rootUrl = 'https://www.agemys.cc';
6
6
  const currentUrl = `${rootUrl}/update`;
7
7
  const response = await got(currentUrl);
8
8
 
9
9
  const $ = cheerio.load(response.data);
10
10
 
11
- const list = $('.anime_icon2_name a')
12
- .map((_, item) => {
11
+ const list = $('.video_item')
12
+ .toArray()
13
+ .map((item) => {
13
14
  item = $(item);
15
+ const link = item.find('a').attr('href').replace('http://', 'https://');
14
16
  return {
15
17
  title: item.text(),
16
- link: `${rootUrl}${item.attr('href')}`,
17
- guid: `${rootUrl}${item.attr('href')}#${item.parent().prev().find('.anime_icon1_name1').text()}`,
18
+ link,
19
+ guid: `${link}#${item.find('.video_item--info').text()}`,
18
20
  };
19
- })
20
- .get();
21
+ });
21
22
 
22
23
  const items = await Promise.all(
23
24
  list.map((item) =>
@@ -25,7 +26,15 @@ module.exports = async (ctx) => {
25
26
  const detailResponse = await got(item.link);
26
27
  const content = cheerio.load(detailResponse.data);
27
28
 
28
- item.description = content('.div_left').html();
29
+ content('img').each((_, ele) => {
30
+ if (ele.attribs['data-original']) {
31
+ ele.attribs.src = ele.attribs['data-original'];
32
+ delete ele.attribs['data-original'];
33
+ }
34
+ });
35
+ content('.video_detail_collect').remove();
36
+
37
+ item.description = content('.video_detail_left').html();
29
38
 
30
39
  return item;
31
40
  })
@@ -0,0 +1,5 @@
1
+ const rootUrl = 'https://www.agemys.org';
2
+
3
+ module.exports = {
4
+ rootUrl,
5
+ };
@@ -1,36 +1,45 @@
1
1
  const got = require('@/utils/got');
2
2
  const cheerio = require('cheerio');
3
- const { rootUrl, ProcessFeed } = require('./utils');
3
+ const timezone = require('@/utils/timezone');
4
+ const { parseDate } = require('@/utils/parse-date');
5
+
6
+ const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
4
7
 
5
8
  module.exports = async (ctx) => {
6
- const id = ctx.params.id;
7
- const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
9
+ const { id } = ctx.params;
10
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
8
11
 
9
- const currentUrl = `${rootUrl}/data/search?column=${id}`;
12
+ const currentUrl = new URL(`/data/search?column=${id}`, rootUrl).href;
10
13
 
11
- const response = await got({
12
- method: 'get',
13
- url: currentUrl,
14
- });
14
+ const { data: response } = await got(currentUrl);
15
15
 
16
- const $ = cheerio.load(response.data);
16
+ const $ = cheerio.load(response);
17
17
 
18
18
  const title = $('div.article-title a').first().text().replace(/\[|\]/g, '');
19
19
 
20
- const items = $('div.search_list a[title]')
20
+ const items = $('div.article-title')
21
+ .slice(0, limit)
21
22
  .toArray()
22
23
  .map((item) => {
23
24
  item = $(item);
24
25
 
26
+ const a = item.find('a[title]');
27
+
25
28
  return {
26
- title: item.text().split(':').pop(),
27
- link: new URL(item.attr('href'), rootUrl).href,
29
+ title: a.text(),
30
+ link: new URL(a.prop('href'), rootUrl).href,
31
+ author: a.text().split(':')[0],
32
+ pubDate: timezone(parseDate(item.find('span').text()), +8),
28
33
  };
29
34
  });
30
35
 
31
36
  ctx.state.data = {
37
+ item: await ProcessFeed(limit, ctx.cache.tryGet, items),
32
38
  title: `爱思想 - ${title}`,
33
39
  link: currentUrl,
34
- item: await ProcessFeed(limit, ctx.cache.tryGet, items),
40
+ description: $('div.tips').text(),
41
+ language: 'zh-cn',
42
+ image: new URL('images/logo.jpg', ossUrl).href,
43
+ subtitle: title,
35
44
  };
36
45
  };
@@ -3,4 +3,5 @@ module.exports = {
3
3
  '/ranking/:id?/:period?': ['HenryQW', 'nczitzk'],
4
4
  '/toplist/:id?/:period?': ['nczitzk'],
5
5
  '/thinktank/:id/:type?': ['hoilc', 'nczitzk'],
6
+ '/zhuanti/:id': ['nczitzk'],
6
7
  };
@@ -8,6 +8,12 @@ module.exports = {
8
8
  source: ['/data/search', '/'],
9
9
  target: (params, url) => `/aisixiang/column/${new URL(url).searchParams.get('column')}`,
10
10
  },
11
+ {
12
+ title: '专题',
13
+ docs: 'https://docs.rsshub.app/reading.html#ai-si-xiang',
14
+ source: ['/zhuanti', '/'],
15
+ target: (params, url) => `/aisixiang/zhuanti/${new URL(url).href.match(/\/zhuanti\/(.*?)\.html/)[1]}`,
16
+ },
11
17
  {
12
18
  title: '排行',
13
19
  docs: 'https://docs.rsshub.app/reading.html#ai-si-xiang',
@@ -3,4 +3,5 @@ module.exports = function (router) {
3
3
  router.get('/ranking/:id?/:period?', require('./toplist'));
4
4
  router.get('/toplist/:id?/:period?', require('./toplist'));
5
5
  router.get('/thinktank/:id/:type?', require('./thinktank'));
6
+ router.get('/zhuanti/:id', require('./zhuanti'));
6
7
  };
@@ -1,20 +1,17 @@
1
1
  const got = require('@/utils/got');
2
2
  const cheerio = require('cheerio');
3
- const { rootUrl, ProcessFeed } = require('./utils');
3
+
4
+ const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
4
5
 
5
6
  module.exports = async (ctx) => {
6
- const id = ctx.params.id;
7
- const type = ctx.params.type ?? '';
8
- const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
7
+ const { id, type = '' } = ctx.params;
8
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
9
9
 
10
- const currentUrl = `${rootUrl}/thinktank/${id}.html`;
10
+ const currentUrl = new URL(`thinktank/${id}.html`, rootUrl).href;
11
11
 
12
- const response = await got({
13
- method: 'get',
14
- url: currentUrl,
15
- });
12
+ const { data: response } = await got(currentUrl);
16
13
 
17
- const $ = cheerio.load(response.data);
14
+ const $ = cheerio.load(response);
18
15
 
19
16
  const title = `${$('h2').first().text().trim()}${type}`;
20
17
 
@@ -31,19 +28,22 @@ module.exports = async (ctx) => {
31
28
  items = [...items, ...$(l).parent().find('ul li a').toArray()];
32
29
  }
33
30
 
34
- items = items.map((item) => {
31
+ items = items.slice(0, limit).map((item) => {
35
32
  item = $(item);
36
33
 
37
34
  return {
38
35
  title: item.text().split(':').pop(),
39
- link: new URL(item.attr('href'), rootUrl).href,
36
+ link: new URL(item.prop('href'), rootUrl).href,
40
37
  };
41
38
  });
42
39
 
43
40
  ctx.state.data = {
41
+ item: await ProcessFeed(limit, ctx.cache.tryGet, items),
44
42
  title: `爱思想 - ${title}`,
45
43
  link: currentUrl,
46
- item: await ProcessFeed(limit, ctx.cache.tryGet, items),
47
44
  description: $('div.thinktank-author-description-box p').text(),
45
+ language: 'zh-cn',
46
+ image: new URL('images/logo_thinktank.jpg', ossUrl).href,
47
+ subtitle: title,
48
48
  };
49
49
  };
@@ -1,37 +1,43 @@
1
1
  const got = require('@/utils/got');
2
2
  const cheerio = require('cheerio');
3
- const { rootUrl, ProcessFeed } = require('./utils');
3
+ const { parseDate } = require('@/utils/parse-date');
4
+
5
+ const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
4
6
 
5
7
  module.exports = async (ctx) => {
6
- const id = ctx.params.id ?? '1';
7
- const period = ctx.params.period ?? '1';
8
- const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
8
+ const { id = '1', period = '1' } = ctx.params;
9
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
9
10
 
10
- const currentUrl = `${rootUrl}/toplist${id ? `?id=${id}${id === '1' ? `&period=${period}` : ''}` : ''}`;
11
+ const currentUrl = new URL(`toplist${id ? `?id=${id}${id === '1' ? `&period=${period}` : ''}` : ''}`, rootUrl).href;
11
12
 
12
- const response = await got({
13
- method: 'get',
14
- url: currentUrl,
15
- });
13
+ const { data: response } = await got(currentUrl);
16
14
 
17
- const $ = cheerio.load(response.data);
15
+ const $ = cheerio.load(response);
18
16
 
19
- const title = `${$('.hl').text() || ''}${$('title').text().split('_')[0]}`;
17
+ const title = `${$('a.hl').text() || ''}${$('title').text().split('_')[0]}`;
20
18
 
21
- const items = $('div.tips a')
19
+ const items = $('div.tops_list')
20
+ .slice(0, limit)
22
21
  .toArray()
23
22
  .map((item) => {
24
23
  item = $(item);
25
24
 
25
+ const a = item.find('div.tips a');
26
+
26
27
  return {
27
- title: item.text().split(':').pop(),
28
- link: new URL(item.attr('href'), rootUrl).href,
28
+ title: a.text(),
29
+ link: new URL(a.prop('href'), rootUrl).href,
30
+ author: item.find('div.name').text(),
31
+ pubDate: parseDate(item.find('div.times').text()),
29
32
  };
30
33
  });
31
34
 
32
35
  ctx.state.data = {
36
+ item: await ProcessFeed(limit, ctx.cache.tryGet, items),
33
37
  title: `爱思想 - ${title}`,
34
38
  link: currentUrl,
35
- item: await ProcessFeed(limit, ctx.cache.tryGet, items),
39
+ language: 'zh-cn',
40
+ image: new URL('images/logo_toplist.jpg', ossUrl).href,
41
+ subtitle: title,
36
42
  };
37
43
  };
@@ -3,28 +3,33 @@ const cheerio = require('cheerio');
3
3
  const timezone = require('@/utils/timezone');
4
4
  const { parseDate } = require('@/utils/parse-date');
5
5
 
6
- const rootUrl = 'http://www.aisixiang.com';
6
+ const ossUrl = 'https://oss.aisixiang.com';
7
+ const rootUrl = 'https://www.aisixiang.com';
7
8
 
8
9
  const ProcessFeed = (limit, tryGet, items) =>
9
10
  Promise.all(
10
11
  items.slice(0, limit).map((item) =>
11
12
  tryGet(item.link, async () => {
12
- const detailResponse = await got({
13
- method: 'get',
14
- url: item.link,
15
- });
13
+ const { data: detailResponse } = await got(item.link);
16
14
 
17
- const content = cheerio.load(detailResponse.data);
15
+ const content = cheerio.load(detailResponse);
18
16
 
19
- item.author = content('strong').first().text();
20
- item.description = content('.article-content').html();
21
- item.pubDate = timezone(parseDate(content('.info').text().split('时间:').pop()), +8);
17
+ const commentMatches = content('h3.comment-header')
18
+ .text()
19
+ .match(/评论(\d+)/);
20
+
21
+ item.title = content('h3').first().text().split(':').pop();
22
+ item.description = content('div.article-content').html();
23
+ item.author = content('div.about strong').first().text();
22
24
  item.category = content('u')
23
25
  .first()
24
26
  .parent()
25
27
  .find('u')
26
28
  .toArray()
27
- .map((a) => content(a).text());
29
+ .map((c) => content(c).text());
30
+ item.pubDate = timezone(parseDate(content('div.info').text().split('时间:').pop()), +8);
31
+ item.upvotes = content('span.like-num').text() ? parseInt(content('span.like-num').text(), 10) : 0;
32
+ item.comments = commentMatches ? parseInt(commentMatches[1], 10) : 0;
28
33
 
29
34
  return item;
30
35
  })
@@ -33,5 +38,6 @@ const ProcessFeed = (limit, tryGet, items) =>
33
38
 
34
39
  module.exports = {
35
40
  rootUrl,
41
+ ossUrl,
36
42
  ProcessFeed,
37
43
  };
@@ -0,0 +1,45 @@
1
+ const got = require('@/utils/got');
2
+ const cheerio = require('cheerio');
3
+ const timezone = require('@/utils/timezone');
4
+ const { parseDate } = require('@/utils/parse-date');
5
+
6
+ const { rootUrl, ossUrl, ProcessFeed } = require('./utils');
7
+
8
+ module.exports = async (ctx) => {
9
+ const { id } = ctx.params;
10
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
11
+
12
+ const currentUrl = new URL(`zhuanti/${id}.html`, rootUrl).href;
13
+
14
+ const { data: response } = await got(currentUrl);
15
+
16
+ const $ = cheerio.load(response);
17
+
18
+ const title = $('div.tips h2').first().text();
19
+
20
+ const items = $('div.article-title')
21
+ .slice(0, limit)
22
+ .toArray()
23
+ .map((item) => {
24
+ item = $(item);
25
+
26
+ const a = item.find('a');
27
+
28
+ return {
29
+ title: a.text(),
30
+ link: new URL(a.prop('href'), rootUrl).href,
31
+ author: a.text().split(':')[0],
32
+ pubDate: timezone(parseDate(item.find('span').text()), +8),
33
+ };
34
+ });
35
+
36
+ ctx.state.data = {
37
+ item: await ProcessFeed(limit, ctx.cache.tryGet, items),
38
+ title: `爱思想 - ${title}`,
39
+ link: currentUrl,
40
+ description: $('div.tips p').text(),
41
+ language: 'zh-cn',
42
+ image: new URL('images/logo_zhuanti.jpg', ossUrl).href,
43
+ subtitle: title,
44
+ };
45
+ };