feat(route): stheadline std (#10642)
This commit is contained in:
parent
e3ffd5d7c1
commit
19dc2857c6
|
|
@ -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"/>
|
||||
|
||||
## 星洲网
|
||||
|
||||
### 首页
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/std/realtime/:category*': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -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}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/std/realtime/:category*', require('./std/realtime'));
|
||||
};
|
||||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue