feat(route): add 壹蘋新聞網 (#10671)
* feat(route): add 壹蘋新聞網 * feat(route): remove comments * docs: fix tag closing
This commit is contained in:
parent
aedf5c8cb7
commit
173c4e6970
|
|
@ -4092,6 +4092,18 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/
|
|||
|
||||
</Route>
|
||||
|
||||
## 壹蘋新聞網
|
||||
|
||||
### 最新新聞
|
||||
|
||||
<Route author="miles170" example="/nextapple/realtime/new" path="/nextapple/realtime/:category?" :paramsDesc="['類別,見下表,默認為最新']">
|
||||
|
||||
| 最新 | 娛樂 | 生活 | 社會 | 政治 | 國際 | 財經 | 飲食旅遊 | 房市 | 時尚 | 車市 | 健康 | 體育 | 3C |
|
||||
| --- | ------------- | ---- | ----- | -------- | ------------- | ------- | --------- | -------- | ------- | ---- | ------ | ------ | ------ |
|
||||
| new | entertainment | life | local | politics | international | finance | lifestyle | property | fashion | auto | health | sports | gadget |
|
||||
|
||||
</Route>
|
||||
|
||||
## 移动支付网
|
||||
|
||||
### 新闻
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/realtime/:category?': ['miles170'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'nextapple.com': {
|
||||
_name: '壹蘋新聞網',
|
||||
tw: [
|
||||
{
|
||||
title: '最新新聞',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#yi-ping-xin-wen-wang',
|
||||
source: ['/', '/realtime/:category'],
|
||||
target: '/nextapple/realtime/:category?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'new';
|
||||
const currentUrl = `https://tw.nextapple.com/realtime/${category}`;
|
||||
const response = await got(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const items = await Promise.all(
|
||||
$('article')
|
||||
.get()
|
||||
.map((item) => {
|
||||
const link = $(item).find('.post-title').attr('href');
|
||||
return ctx.cache.tryGet(link, async () => {
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const mainContent = $('#main-content');
|
||||
const titleElement = mainContent.find('header h1');
|
||||
const title = titleElement.text();
|
||||
titleElement.remove();
|
||||
const postMetaElement = mainContent.find('.post-meta');
|
||||
const category = postMetaElement.find('.category').text();
|
||||
const pubDate = parseDate(postMetaElement.find('time').attr('datetime'));
|
||||
postMetaElement.remove();
|
||||
$('.post-comments').remove();
|
||||
|
||||
return {
|
||||
title,
|
||||
description: mainContent.html(),
|
||||
category,
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/realtime/:category?', require('./realtime'));
|
||||
};
|
||||
Loading…
Reference in New Issue