diff --git a/docs/new-media.md b/docs/new-media.md index cce548e6c..385d99369 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -635,6 +635,18 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## NGOCN + +### 首页 + + + +| 所有文章 | 早报 | 热点 | +| -------- | ----------- | -------- | +| article | daily-brief | trending | + + + ## Netflix ### Newsroom diff --git a/lib/v2/ngocn2/index.js b/lib/v2/ngocn2/index.js new file mode 100644 index 000000000..74a050ba8 --- /dev/null +++ b/lib/v2/ngocn2/index.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'article'; + + const rootUrl = 'https://ngocn2.org'; + const currentUrl = `${rootUrl}/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.articleroll__article a') + .map((_, item) => { + item = $(item); + + return { + title: item.find('.title').text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.find('.meta').text()), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.gatsby-resp-image-link').each(function () { + content(this).html(``); + }); + + item.description = content('.article__content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.sectitle__content').text()} - NGOCN`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/ngocn2/maintainer.js b/lib/v2/ngocn2/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/ngocn2/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/ngocn2/radar.js b/lib/v2/ngocn2/radar.js new file mode 100644 index 000000000..c05838275 --- /dev/null +++ b/lib/v2/ngocn2/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ngocn2.org': { + _name: 'NGOCN', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#ngocn2-fen-lei', + source: ['/'], + target: '/ngocn2/:category?', + }, + ], + }, +}; diff --git a/lib/v2/ngocn2/router.js b/lib/v2/ngocn2/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/ngocn2/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +};