feat(route): add NGOCN (#8301)
Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:category?': ['nczitzk'],
|
||||
};
|
||||
@@ -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?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/:category?', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user