diff --git a/docs/new-media.md b/docs/new-media.md index 3bdd24997..dfa0fcbdd 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -777,6 +777,10 @@ area 分区选项 ## 观察者网 +### 头条 + + + ### 首页 diff --git a/lib/router.js b/lib/router.js index 1cd5df7d7..b6fead7b4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1700,6 +1700,7 @@ router.get('/zfrontier/postlist/:type', require('./routes/zfrontier/postlist')); router.get('/zfrontier/board/:boardId', require('./routes/zfrontier/board_postlist')); // 观察者网 +router.get('/guancha/headline', require('./routes/guancha/headline')); router.get('/guancha/topic/:id/:order?', require('./routes/guancha/topic')); router.get('/guancha/member/:caty?', require('./routes/guancha/member')); router.get('/guancha/personalpage/:uid', require('./routes/guancha/personalpage')); diff --git a/lib/routes/guancha/headline.js b/lib/routes/guancha/headline.js new file mode 100644 index 000000000..ea8e5a88e --- /dev/null +++ b/lib/routes/guancha/headline.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.guancha.cn'; + const currentUrl = `${rootUrl}/GuanChaZheTouTiao/list_1.shtml`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.headline-list li .content-headline h3 a') + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + description: item.parent().next().html(), + pubDate: new Date(item.parents('div').eq(0).find('span').text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description += content('.all-txt').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '观察者网 - 头条', + link: currentUrl, + item: items, + }; +};