feat(route): add NGOCN (#8301)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Ethan Shen
2021-11-27 07:58:17 +00:00
committed by GitHub
co-authored by DIYgod
parent 0e952af6f0
commit 3936d67139
5 changed files with 87 additions and 0 deletions
+12
View File
@@ -635,6 +635,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
<Route author="emdoe" example="/nautilus/topic/Art" path="/nautilus/topic/:tid" :paramsDesc="['话题 id, 可在页面上方 TOPICS 栏目处找到']"/>
## NGOCN
### 首页
<Route author="nczitzk" example="/ngocn2" path="/ngocn2/:category?" :paramsDesc="['分类,见下表,默认为所有文章']" radar="1" rssbud="1">
| 所有文章 | 早报 | 热点 |
| -------- | ----------- | -------- |
| article | daily-brief | trending |
</Route>
## Netflix
### Newsroom
+56
View File
@@ -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(`<img src="${content(this).find('img').attr('src')}">`);
});
item.description = content('.article__content').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('.sectitle__content').text()} - NGOCN`,
link: currentUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
+13
View File
@@ -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?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./index'));
};