mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
Add(route): add 蘋果新聞網 (#8821)
This commit is contained in:
@@ -1110,6 +1110,18 @@ category 对应的关键词有
|
||||
|
||||
</Route>
|
||||
|
||||
## 苹果新闻网
|
||||
|
||||
<Route author="Fatpandac" example="/appledaily/home" path="/appledaily/:channel?" :paramsDesc="['频道,默认为主页']">
|
||||
|
||||
频道参数均可在官网获取,如:
|
||||
|
||||
`https://tw.appledaily.com/realtime/micromovie/` 对应 `/appledaily/micromovie`
|
||||
|
||||
`https://tw.appledaily.com/home/` 对应 `/appledaily/home`
|
||||
|
||||
</Route>
|
||||
|
||||
## 齐鲁晚报
|
||||
|
||||
### 新闻
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const path = require('path');
|
||||
const { art } = require('@/utils/render');
|
||||
|
||||
const rootUrl = 'https://tw.appledaily.com';
|
||||
|
||||
const channelMap = {
|
||||
home: '首頁',
|
||||
recommend: '焦点',
|
||||
new: '最新',
|
||||
hot: '热门',
|
||||
life: '生活',
|
||||
entertainment: '娱乐',
|
||||
local: '社会',
|
||||
property: '财经地产',
|
||||
international: '国际',
|
||||
politics: '政治',
|
||||
gadget: '3C车城',
|
||||
supplement: '吃喝玩乐',
|
||||
sports: '体育',
|
||||
forum: '苹评理',
|
||||
micromovie: '微视频',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const channel = ctx.params.channel ?? 'home';
|
||||
const url = `${rootUrl}${channel === 'home' ? '/home' : `/realtime/${channel}`}`;
|
||||
|
||||
const response = await got.get(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.flex-feature')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
|
||||
.map((_, item) => {
|
||||
const title = $(item).find('span.headline').text();
|
||||
const link = rootUrl + $(item).find('a').attr('href');
|
||||
const pubDate = parseDate($(item).find('div.timestamp').text(), 'YYYY/MM/DD HH:mm');
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
pubDate,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got.get(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const dataJs = content('script#fusion-metadata').html();
|
||||
const descDataJSON = JSON.parse(dataJs.match(/Fusion.globalContent=(.*);Fusion.globalConte/)[1]);
|
||||
item.description = art(path.join(__dirname, 'templates/content.art'), {
|
||||
content_elements: descDataJSON.content_elements,
|
||||
});
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `蘋果日報 - ${channelMap[channel]}`,
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:channel?': ['Fatpandac'],
|
||||
};
|
||||
@@ -0,0 +1,157 @@
|
||||
module.exports = {
|
||||
'appledaily.com': {
|
||||
_name: '苹果新闻网',
|
||||
tw: [
|
||||
{
|
||||
title: '首頁',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'home') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '焦点',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'recommend') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '最新',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'new') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '热门',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'hot') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '生活',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'life') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '娱乐',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'entertainment') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '社会',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'local') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '财经地产',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'property') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '国际',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'international') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '政治',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'politics') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '3C车城',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'gadget') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '吃喝玩乐',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'supplement') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '体育',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'sports') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '苹评理',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'forum') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '微视频',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ping-guo-xin-wen-wang',
|
||||
source: ['/realtime/:channel'],
|
||||
target: (params) => {
|
||||
if (params.channel === 'micromovie') {
|
||||
return '/appledaily/:channel';
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/:channel?', require('./index'));
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
{{ each content_elements }}
|
||||
{{ if $value.type === 'image' }}
|
||||
<img src="{{ $value.url }}" alt="{{ $value.caption }}"/>
|
||||
{{ else if $value.type === 'text' }}
|
||||
<p>{{ $value.content }}</p>
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
Reference in New Issue
Block a user