diff --git a/docs/README.md b/docs/README.md
index edb14719b7..ab27e4d510 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1870,6 +1870,8 @@ Category 列表:
+
+
### 联合早报
diff --git a/lib/router.js b/lib/router.js
index ea92b3578d..ea16999bb1 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -704,6 +704,7 @@ router.get('/embassy/:country/:city?', require('./routes/embassy/index'));
// 澎湃新闻
router.get('/thepaper/featured', require('./routes/thepaper/featured'));
+router.get('/thepaper/channel/:id', require('./routes/thepaper/channel'));
// 电影首发站
router.get('/dysfz', require('./routes/dysfz/index'));
diff --git a/lib/routes/thepaper/channel.js b/lib/routes/thepaper/channel.js
new file mode 100644
index 0000000000..009ea21fd4
--- /dev/null
+++ b/lib/routes/thepaper/channel.js
@@ -0,0 +1,13 @@
+const utils = require('./utils');
+
+module.exports = async (ctx) => {
+ const { id } = ctx.params;
+ const link = `https://m.thepaper.cn/list_${id}`;
+ const items = await utils.ProcessFeed(link, ctx);
+
+ ctx.state.data = {
+ title: `澎湃新闻频道 - ${id}`,
+ link,
+ item: items,
+ };
+};
diff --git a/lib/routes/thepaper/featured.js b/lib/routes/thepaper/featured.js
index 8f167da0ff..f4b18ad237 100644
--- a/lib/routes/thepaper/featured.js
+++ b/lib/routes/thepaper/featured.js
@@ -1,66 +1,12 @@
-const cheerio = require('cheerio');
-const dayjs = require('dayjs');
-const url = require('url');
-const axios = require('../../utils/axios');
+const utils = require('./utils');
module.exports = async (ctx) => {
- const axios_ins = axios.create({
- headers: {
- 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1',
- },
- });
-
const link = 'https://m.thepaper.cn/';
-
- const res = await axios_ins.get(link);
-
- const data = res.data;
- const $ = cheerio.load(data);
- const list = $('p.news_tit01, div.news_tit02')
- .slice(0, 10)
- .get();
-
- const out = await Promise.all(
- list.map(async (item) => {
- const $ = cheerio.load(item);
- const itemUrl = url.resolve(
- link,
- $(item)
- .find('a')
- .attr('href')
- );
- const cache = await ctx.cache.get(itemUrl);
- if (cache) {
- return Promise.resolve(JSON.parse(cache));
- }
- const res = await axios_ins.get(itemUrl);
- const content = cheerio.load(res.data);
- const serverOffset = new Date().getTimezoneOffset() / 60;
- const single = {
- title: $(item)
- .find('a')
- .text(),
- guid: itemUrl,
- link: itemUrl.replace('https://m.', 'https://'),
- description: content('#v3cont_id > div.news_content > div.news_part_father > div > div:nth-child(1)').html(),
- pubDate: content('#v3cont_id > div.news_content > p:nth-child(3)').html()
- ? dayjs(
- content('#v3cont_id > div.news_content > p:nth-child(3)')
- .html()
- .split(' ')[0]
- )
- .add(-8 - serverOffset, 'hour')
- .toISOString()
- : null,
- author: content('#v3cont_id > div.news_content > p:nth-child(2)').text(),
- };
- return Promise.resolve(single);
- })
- );
+ const items = await utils.ProcessFeed(link, ctx);
ctx.state.data = {
title: '澎湃新闻 - 首页头条',
link,
- item: out,
+ item: items,
};
};
diff --git a/lib/routes/thepaper/utils.js b/lib/routes/thepaper/utils.js
new file mode 100644
index 0000000000..09059bc985
--- /dev/null
+++ b/lib/routes/thepaper/utils.js
@@ -0,0 +1,60 @@
+const cheerio = require('cheerio');
+const dayjs = require('dayjs');
+const url = require('url');
+const axios = require('../../utils/axios');
+
+module.exports = {
+ ProcessFeed: async (link, ctx) => {
+ const axios_ins = axios.create({
+ headers: {
+ 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1',
+ },
+ });
+
+ const res = await axios_ins.get(link);
+
+ const data = res.data;
+ const $ = cheerio.load(data);
+ const list = $('p.news_tit01, div.news_tit02')
+ .slice(0, 10)
+ .get();
+
+ return await Promise.all(
+ list.map(async (item) => {
+ const $ = cheerio.load(item);
+ const itemUrl = url.resolve(
+ link,
+ $(item)
+ .find('a')
+ .attr('href')
+ );
+ const cache = await ctx.cache.get(itemUrl);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+ const res = await axios_ins.get(itemUrl);
+ const content = cheerio.load(res.data);
+ const serverOffset = new Date().getTimezoneOffset() / 60;
+ const single = {
+ title: $(item)
+ .find('a')
+ .text(),
+ guid: itemUrl,
+ link: itemUrl.replace('https://m.', 'https://'),
+ description: content('#v3cont_id > div.news_content > div.news_part_father > div > div:nth-child(1)').html(),
+ pubDate: content('#v3cont_id > div.news_content > p:nth-child(3)').html()
+ ? dayjs(
+ content('#v3cont_id > div.news_content > p:nth-child(3)')
+ .html()
+ .split(' ')[0]
+ )
+ .add(-8 - serverOffset, 'hour')
+ .toISOString()
+ : null,
+ author: content('#v3cont_id > div.news_content > p:nth-child(2)').text(),
+ };
+ return Promise.resolve(single);
+ })
+ );
+ },
+};