feat(route): add 8视界 (#8262)

This commit is contained in:
Ethan Shen
2021-09-25 19:13:08 -07:00
committed by GitHub
parent 7065f51881
commit 3441822d74
5 changed files with 88 additions and 0 deletions
+12
View File
@@ -44,6 +44,18 @@ pageClass: routes
<Route author="nczitzk" example="/36kr/user/747305693" path="/36kr/user/:uid" :paramsDesc="['用户ID']" />
## 8 视界
### 分类
<Route author="nczitzk" example="/8world" path="/8world/:category?" :paramsDesc="['分类,见下表,默认为即时']">
| 即时 | 新加坡 | 东南亚 | 中港台 | 国际 | 财经 | 体育 |
| -------- | --------- | -------------- | ------------- | ----- | ------- | ------ |
| realtime | singapore | southeast-asia | greater-china | world | finance | sports |
</Route>
### 主题文章
<Route author="nczitzk" example="/36kr/motif/452" path="/36kr/motif/:mid" :paramsDesc="['主题ID']" />
+57
View File
@@ -0,0 +1,57 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'realtime';
const rootUrl = 'https://www.8world.com';
const currentUrl = `${rootUrl}/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div[data-column="Two-Third"] .article-title .article-link')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.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);
item.description = content('.text-long').html();
item.title = content('meta[name="cXenseParse:mdc-title"]').attr('content');
item.author = content('meta[name="cXenseParse:author"]').attr('content');
item.pubDate = parseDate(content('meta[name="cXenseParse:recs:publishtime"]').attr('content'));
item.category = content('meta[name="cXenseParse:mdc-keywords"]')
.toArray()
.map((keyword) => content(keyword).attr('content'));
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'8world.com': {
_name: '8视界',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/new-media.html#_8-shi-jie-fen-lei',
source: ['/:category', '/'],
target: '/8world/:category?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./index'));
};