feat(route): add 星洲网 (#10167)
This commit is contained in:
parent
f0a838eb2a
commit
dde57522ae
|
|
@ -1740,6 +1740,33 @@ category 对应的关键词有
|
|||
|
||||
</Route>
|
||||
|
||||
## 星洲网
|
||||
|
||||
### 首页
|
||||
|
||||
<Route author="nczitzk" example="/sinchew" path="/sinchew" />
|
||||
|
||||
### 最新
|
||||
|
||||
<Route author="nczitzk" example="/sinchew/latest" path="/sinchew/latest" />
|
||||
|
||||
### 分类
|
||||
|
||||
<Route author="nczitzk" example="/sinchew/category/头条" path="/sinchew/category/:category?" :paramsDesc="['分类,见下表,亦可以在对应分类页 URL 中找到']">
|
||||
|
||||
| 头条 | 国内 | 国际 | 言路 | 财经 | 地方 | 副刊 | 娱乐 | 体育 | 百格 | 星角攝 | 好运来 |
|
||||
| -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --- | --- |
|
||||
|
||||
::: tip 提示
|
||||
|
||||
若订阅单级分类 [头条](https://www.sinchew.com.my/category/头条),其 URL 为 [https://www.sinchew.com.my/category/ 头条](https://www.sinchew.com.my/category/头条),则路由为 [`/sinchew/category/头条`](https://rsshub.app/sinchew/category/头条)。
|
||||
|
||||
若订阅多级分类 [国际 > 天下事](https://www.sinchew.com.my/category/国际/天下事),其 URL 为 [https://www.sinchew.com.my/category/ 国际 / 天下事](https://www.sinchew.com.my/category/国际/天下事),则路由为 [`/sinchew/category/国际/天下事`](https://rsshub.app/sinchew/category/国际/天下事)。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 央视新闻
|
||||
|
||||
### 新闻联播
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.sinchew.com.my';
|
||||
const currentUrl = `${rootUrl}${ctx.path === '/' ? '' : ctx.path}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('.title .internalLink')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
title: item.attr('data-title'),
|
||||
link: /^http/.test(link) ? link : `${rootUrl}${link}`,
|
||||
pubDate: timezone(parseDate(item.text()), +8),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.ads-frame, .read-more-msg').remove();
|
||||
|
||||
content('figure').each(function () {
|
||||
content(this).replaceWith(
|
||||
art(path.join(__dirname, 'templates/images.art'), {
|
||||
image: content(this).find('img').attr('src'),
|
||||
caption: content(this).find('figcaption').text(),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
item.description = content('.article-page-content').html();
|
||||
item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
'/category/:category?': ['nczitzk'],
|
||||
'/latest': ['nczitzk'],
|
||||
'/': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = {
|
||||
'sinchew.com.my': {
|
||||
_name: '星洲网',
|
||||
'.': [
|
||||
{
|
||||
title: '首页',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xing-zhou-wang-shou-ye',
|
||||
source: ['/'],
|
||||
target: '/sinchew',
|
||||
},
|
||||
{
|
||||
title: '最新',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xing-zhou-wang-zui-xin',
|
||||
source: ['/latest', '/'],
|
||||
target: '/sinchew/latest',
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#xing-zhou-wang-fen-lei',
|
||||
source: ['/category/:category', '/'],
|
||||
target: (params, url) => `/sinchew/category/${new URL(url).toString().match(/\/category\/(.*)$/)[1]}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get(/([\w/-]+)?/, require('./index'));
|
||||
router.get('', require('./index'));
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<figure>
|
||||
<img src="{{ image }}">
|
||||
<figcaption>{{ caption }}</figcaption>
|
||||
</figure>
|
||||
Loading…
Reference in New Issue