mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-29 18:06:31 +08:00
feat(route): hakkatv (#10170)
This commit is contained in:
@@ -1113,6 +1113,18 @@ category 对应的关键词有
|
||||
|
||||
<Route author="wushijishan nczitzk" example="/kaopunews/:language?" path="/kaopunews" :paramsDesc="['语言,可选 zh-hans 即简体中文,或 zh-hant 即繁体中文']"/>
|
||||
|
||||
## 客家電視台
|
||||
|
||||
### 新聞首頁
|
||||
|
||||
<Route author="TonyRL" example="/hakkatv/news" path="/hakkatv/news/:type?" :paramsDesc="['新聞,見下表,留空為全部']" radar="1" rssbud="1">
|
||||
|
||||
| 客家焦點 | 政經要聞 | 民生醫療 | 地方風采 | 國際萬象 |
|
||||
| ----- | --------- | ------- | ----- | ------------- |
|
||||
| hakka | political | medical | local | international |
|
||||
|
||||
</Route>
|
||||
|
||||
## 理论网
|
||||
|
||||
### 学习时报
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/news/:type?': ['TonyRL'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'hakkatv.org.tw': {
|
||||
_name: '客家電視台',
|
||||
'.': [
|
||||
{
|
||||
title: '新聞首頁 - 客家電視台',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#ke-jia-dian-shi-tai',
|
||||
source: '/news',
|
||||
target: '/hakkatv/news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/news/:type?', require('./type'));
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const typeMap = ['hakka', 'political', 'medical', 'local', 'international'];
|
||||
const baseUrl = 'https://www.hakkatv.org.tw';
|
||||
const apiUrl = 'https://api.hakkatv.org.tw';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { type } = ctx.params;
|
||||
|
||||
let allData;
|
||||
if (!type) {
|
||||
allData = await Promise.all(
|
||||
typeMap.map(async (t) => {
|
||||
const { data } = await got(`${apiUrl}/api/news/index`, {
|
||||
searchParams: {
|
||||
per: 4,
|
||||
'sort[created_at]': 'desc',
|
||||
type: t,
|
||||
keywords: '',
|
||||
},
|
||||
});
|
||||
return data.data;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
allData = (
|
||||
await got(`${apiUrl}/api/news/index`, {
|
||||
searchParams: {
|
||||
per: 4,
|
||||
'sort[created_at]': 'desc',
|
||||
type,
|
||||
keywords: '',
|
||||
},
|
||||
})
|
||||
).data.data;
|
||||
}
|
||||
|
||||
const list = [].concat(...allData).map((item) => ({
|
||||
title: item.title,
|
||||
pubDate: timezone(parseDate(item.created_at), +8),
|
||||
author: item.author,
|
||||
link: `${baseUrl}/news-detail/${item.id}`,
|
||||
id: item.id,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data } = await got(`${apiUrl}/api/news/read/${item.id}`);
|
||||
item.category = data.tag.map((t) => t.tag);
|
||||
item.description = data.content.replace(/\n/g, '<br>');
|
||||
delete item.id;
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '新聞首頁 - 客家電視台',
|
||||
description: '客家電視是屬於全民、以至於全世界客家族群的頻道,亦是為傳播客家文化而存在,定位為「全體客家族群之媒體」。',
|
||||
link: `${baseUrl}/news`,
|
||||
language: 'zh-TW',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -40,6 +40,7 @@ module.exports = async (ctx) => {
|
||||
ctx.state.data = {
|
||||
title: $('head title').text(),
|
||||
link: url,
|
||||
language: 'zh-TW',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user