feat(route): stheadline std (#10642)

This commit is contained in:
Tony 2022-08-28 16:44:40 -06:00 committed by GitHub
parent e3ffd5d7c1
commit 19dc2857c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 0 deletions

View File

@ -1985,6 +1985,12 @@ category 对应的关键词有
</Route>
## 星島日報
### 即時
<Route author="TonyRL" example="/stheadline/std/realtime/即時" path="/stheadline/std/realtime/:category*" :paramsDesc="['分類路徑URL 中 `/realtime/` 後的部分,預設為`即時`']" radar ="1" rssbud="1"/>
## 星洲网
### 首页

View File

@ -0,0 +1,3 @@
module.exports = {
'/std/realtime/:category*': ['TonyRL'],
};

View File

@ -0,0 +1,13 @@
module.exports = {
'stheadline.com': {
_name: '星島日報',
std: [
{
title: '即時',
docs: 'https://docs.rsshub.app/traditional-media.html#xing-dao-ri-bao',
source: ['/realtime/*category'],
target: (params) => `/stdheadline/std/realtime/${params.category}`,
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/std/realtime/:category*', require('./std/realtime'));
};

View File

@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const baseUrl = 'https://std.stheadline.com';
module.exports = async (ctx) => {
const { category = '即時' } = ctx.params;
const url = `${baseUrl}/realtime/${category}`;
const { data: response } = await got(url);
const $ = cheerio.load(response);
const items = $('.col-md-9 .media-body .h5 a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.attr('title'),
link: item.attr('href'),
guid: item.attr('href').substring(0, item.attr('href').lastIndexOf('/')),
};
});
await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('.paragraphs').html();
item.pubDate = timezone(parseDate($('.content .date').text()));
return item;
})
)
);
ctx.state.data = {
title: $('head title').text(),
description: $('meta[name=description]').attr('content'),
image: 'https://std.stheadline.com/dist/images/favicon/icon-512.png',
link: url,
item: items,
};
};