diff --git a/docs/new-media.md b/docs/new-media.md index 2d5d0cc19..365d1097c 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -524,6 +524,12 @@ Country +## Good.news + +### 今日要闻 + + + ## GQ ### GQ 台湾 diff --git a/lib/v2/good/index.js b/lib/v2/good/index.js new file mode 100644 index 000000000..55da0dd2c --- /dev/null +++ b/lib/v2/good/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://good.news'; + + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.content-structure') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50) + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('h4 a'); + + return { + title: a.text(), + link: a.attr('href'), + pubDate: parseDate(item.find('.content-left').text()), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('div[contentscore]').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'good.news - 今日要闻', + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/good/maintainer.js b/lib/v2/good/maintainer.js new file mode 100644 index 000000000..ca7cf1eb1 --- /dev/null +++ b/lib/v2/good/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['nczitzk'], +}; diff --git a/lib/v2/good/radar.js b/lib/v2/good/radar.js new file mode 100644 index 000000000..aac7e093c --- /dev/null +++ b/lib/v2/good/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'good.news': { + _name: 'Good.news', + '.': [ + { + title: '今日要闻', + docs: 'https://docs.rsshub.app/new-media.html#good-news-jin-ri-yao-wen', + source: ['/'], + target: '/good', + }, + ], + }, +}; diff --git a/lib/v2/good/router.js b/lib/v2/good/router.js new file mode 100644 index 000000000..20c52b09d --- /dev/null +++ b/lib/v2/good/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./index')); +};