From 073df65935f3d052d3ecffad99a07bac4a48099d Mon Sep 17 00:00:00 2001
From: Fatpandac <1779196284@qq.com>
Date: Thu, 10 Mar 2022 02:26:54 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=B8=8C=E6=9C=9B?=
=?UTF-8?q?=E4=B9=8B=E5=A3=B0=20(#9285)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 希望之声
* fix(route): change timezone
---
docs/traditional-media.md | 14 ++++++++++-
lib/v2/soundofhope/channel.js | 42 ++++++++++++++++++++++++++++++++
lib/v2/soundofhope/maintainer.js | 3 +++
lib/v2/soundofhope/radar.js | 13 ++++++++++
lib/v2/soundofhope/router.js | 3 +++
5 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 lib/v2/soundofhope/channel.js
create mode 100644 lib/v2/soundofhope/maintainer.js
create mode 100644 lib/v2/soundofhope/radar.js
create mode 100644 lib/v2/soundofhope/router.js
diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index 63398ee96..dda316069 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -1298,6 +1298,16 @@ category 对应的关键词有
+## 希望之声
+
+
+
+参数均可在官网获取,如:
+
+`https://www.soundofhope.org/term/203` 对应 `/soundofhope/term/203`
+
+
+
## 香港 01
### 热门
@@ -1598,7 +1608,7 @@ category 对应的关键词有
## 自由亚洲电台
-
+
通过指定频道参数,提供比官方源更佳的阅读体验。
@@ -1607,3 +1617,5 @@ category 对应的关键词有
`https://www.rfa.org/cantonese/news` 对应 `/rfa/cantonese/news`
`https://www.rfa.org/cantonese/news/htm` 对应 `/rfa/cantonese/news/htm`
+
+
diff --git a/lib/v2/soundofhope/channel.js b/lib/v2/soundofhope/channel.js
new file mode 100644
index 000000000..41ee34aa8
--- /dev/null
+++ b/lib/v2/soundofhope/channel.js
@@ -0,0 +1,42 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+const timezone = require('@/utils/timezone');
+
+const host = 'https://www.soundofhope.org';
+
+module.exports = async (ctx) => {
+ const channel = ctx.params.channel;
+ const id = ctx.params.id;
+ const url = `${host}/${channel}/${id}`;
+
+ const response = await got(url);
+ const $ = cheerio.load(response.data);
+ const title = $('div.left > nav').text().split('/').slice(1).join('');
+ const list = $('div.item')
+ .map((_, item) => ({
+ title: $(item).find('div.title').text(),
+ link: new URL($(item).find('a').attr('href'), host).href,
+ }))
+ .get();
+
+ const items = await Promise.all(
+ list.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got(item.link);
+ const content = cheerio.load(detailResponse.data);
+
+ item.description = content('div.Content__Wrapper-sc-1bvya0-0').html();
+ item.pubDate = timezone(parseDate(content('div.date').text(), 'YYYY.M.D HH:mm'), -8);
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: `希望之声 - ${title}`,
+ link: url,
+ item: items,
+ };
+};
diff --git a/lib/v2/soundofhope/maintainer.js b/lib/v2/soundofhope/maintainer.js
new file mode 100644
index 000000000..f510bcc5b
--- /dev/null
+++ b/lib/v2/soundofhope/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/:channel/:id': ['Fatpandac'],
+};
diff --git a/lib/v2/soundofhope/radar.js b/lib/v2/soundofhope/radar.js
new file mode 100644
index 000000000..67b8fc0d4
--- /dev/null
+++ b/lib/v2/soundofhope/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'soundofhope.org': {
+ _name: '希望之声',
+ '.': [
+ {
+ title: '频道',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xi-wang-zhi-sheng',
+ source: ['/:channel/:id'],
+ target: '/soundofhope/:channel/:id',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/soundofhope/router.js b/lib/v2/soundofhope/router.js
new file mode 100644
index 000000000..627fc60cc
--- /dev/null
+++ b/lib/v2/soundofhope/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/:channel/:id', require('./channel'));
+};