WIP: add Media Digest

This commit is contained in:
Toby Tso 2020-12-29 19:59:57 +08:00
parent 473cc49d02
commit 961636aebd
2 changed files with 25 additions and 6 deletions

View File

@ -957,3 +957,20 @@ category 对应的关键词有
### 九江新闻
<Route author="jjlzg" example="/fjnews/jjnews" path="/fjnews/jjnews"/>
### RTHK 傳媒透視
<Route author="tpnonthealps" example="/mediadigest/latest" path="/mediadigest/:range" :paramsDesc="['时间范围']">
细则:
- `:range` 时间范围参数
(可为 `latest``四位数字的年份`)
- `latest`: 最新的 50 篇文章
- `2020`: 2020 年的所有文章
- 全文输出转换为简体字: `?opencc=t2s`
(`opencc` 是 RSSHub 的通用参数,详情请参阅 [「中文简繁体转换」](https://docs.rsshub.app/parameter.html#zhong-wen-jian-fan-ti-zhuan-huan))
</Route>

View File

@ -39,10 +39,11 @@ module.exports = async (ctx) => {
// for range validation
const num = /^[1-9][0-9]{3}$/;
const current_year = new Date().getFullYear();
// placeholder for rss
// placeholders
let title = '傳媒透視';
let rss = [
{
description: '<p>Invalid <code>:category?</code> input.</p><p>所輸入<code>:category?</code>參數有誤。</p><p>所输入<code>:category?</code>参数有误。</p>',
description: '<p>Invalid <code>:range</code> input.</p><p>所輸入<code>:range</code>參數有誤。</p><p>所输入<code>:range</code>参数有误。</p>',
},
];
// cid
@ -53,7 +54,7 @@ module.exports = async (ctx) => {
// latest (50 articles):
// if 'all' (latest 50 articles of the site);
// else if 'cid' (all articles of a specific category);
// else if 'cid' (deprecated) (latest 50 articles of a specific category);
// else 'error'.
if (range === 'latest') {
if (category === 'all') {
@ -91,7 +92,7 @@ module.exports = async (ctx) => {
}
}
// year (specific year range):
// if 'all' (all articles in a specific year range);
// if 'all' (latest 200 articles in a specific year range);
// else 'error'.
else if (num.test(range)) {
const range_num = parseInt(range);
@ -117,12 +118,13 @@ module.exports = async (ctx) => {
})
);
const list = [...new Set(list_all.flat())]; // removed duplicates and flatten
rss = await getArticle(ctx, list.slice(0, 50));
rss = await getArticle(ctx, list.slice(0, 200));
title = `傳媒透視 - ${range}`;
}
}
ctx.state.data = {
title: '傳媒透視',
title: title,
link: 'https://app3.rthk.hk/mediadigest/index.php',
item: rss,
};