From 6f51cc09b383f383c1bbef55e0d2ac85bce04483 Mon Sep 17 00:00:00 2001
From: MisteryMonster <40703811+MisteryMonster@users.noreply.github.com>
Date: Wed, 20 May 2020 19:46:09 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E3=80=8A=E9=A6=99?=
=?UTF-8?q?=E6=B8=AF01=E3=80=8B=20=E9=9B=B7=E8=BE=BE=E6=94=AF=E6=8C=81&&?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E3=80=8A=E9=A6=99=E6=B8=AF=2001=E3=80=8B?=
=?UTF-8?q?=E5=91=A8=E6=8A=A5=E8=AE=A2=E9=98=85=20(#4786)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
assets/radar-rules.js | 43 +++++++++++++++++++
docs/traditional-media.md | 14 ++++---
lib/router.js | 1 +
lib/routes/hk01/ebook.js | 87 +++++++++++++++++++++++++++++++++++++++
4 files changed, 140 insertions(+), 5 deletions(-)
mode change 100755 => 100644 assets/radar-rules.js
create mode 100644 lib/routes/hk01/ebook.js
diff --git a/assets/radar-rules.js b/assets/radar-rules.js
old mode 100755
new mode 100644
index 74d97fe61..3c8a95ff7
--- a/assets/radar-rules.js
+++ b/assets/radar-rules.js
@@ -1955,4 +1955,47 @@
},
],
},
+ 'hk01.com': {
+ _name: '香港01',
+ www: [
+ {
+ title: '最 Hit',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: ['/hot', '/'],
+ target: '/hk01/hot',
+ },
+ {
+ title: 'zone',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: '/zone/:id/:title',
+ target: '/hk01/zone/:id',
+ },
+ {
+ title: 'channel',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: '/channel/:id/:title',
+ target: '/hk01/channel/:id',
+ },
+ {
+ title: 'issue',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: '/issue/:id/:title',
+ target: '/hk01/issue/:id',
+ },
+ {
+ title: 'tag',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: '/tag/:id/:title',
+ target: '/hk01/tag/:id',
+ },
+ ],
+ ebook: [
+ {
+ title: '《香港01》周报',
+ docs: 'https://docs.rsshub.app/traditional-media.html#xiang-gang-01',
+ source: ['/', '/subscribe'],
+ target: '/hk01/ebook',
+ },
+ ],
+ },
});
diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index 1ec2b0d06..486697fb9 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -423,23 +423,27 @@ category 对应的关键词有
### 热门
-
+
### 栏目
-
+
### 子栏目
-
+
### 专题
-
+
### 标签
-
+
+
+### 《香港 01》周报
+
+
## 香港電台
diff --git a/lib/router.js b/lib/router.js
index 96a181b92..16a77254e 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2134,6 +2134,7 @@ router.get('/hk01/channel/:id', require('./routes/hk01/channel'));
router.get('/hk01/issue/:id', require('./routes/hk01/issue'));
router.get('/hk01/tag/:id', require('./routes/hk01/tag'));
router.get('/hk01/hot', require('./routes/hk01/hot'));
+router.get('/hk01/ebook', require('./routes/hk01/ebook'));
// 码农周刊
router.get('/manong-weekly', require('./routes/manong-weekly/issues'));
diff --git a/lib/routes/hk01/ebook.js b/lib/routes/hk01/ebook.js
new file mode 100644
index 000000000..ef47c3b02
--- /dev/null
+++ b/lib/routes/hk01/ebook.js
@@ -0,0 +1,87 @@
+const got = require('@/utils/got');
+const dayjs = require('dayjs');
+
+module.exports = async (ctx) => {
+ const tokenresponse = await got({
+ method: 'get',
+ url: `https://emag-api.hk01.com/v1/access_token`,
+ });
+ const hk01Authorization = tokenresponse.data.data[0].token;
+ const response = await got({
+ method: 'get',
+ url: `https://emag-api.hk01.com/v1/books?devices=web&sourceId=72&p=1&pnum=8&itm_source=service_entrance&itm_medium=web&source_id=72&`,
+ headers: {
+ Authorization: hk01Authorization,
+ },
+ });
+ const issuedata = response.data.data[0];
+ // 获取最近周刊的文章
+ const link = `https://emag-api.hk01.com/v1/toc?bookId=${issuedata.book_id}`;
+ const cache = await ctx.cache.get(link);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+
+ const response2 = await got({
+ method: 'get',
+ url: link,
+ headers: {
+ Authorization: hk01Authorization,
+ },
+ });
+ // 返回单个的issue下的内容。
+ const data2 = response2.data.data;
+ const single = await Promise.all(
+ data2.map(async (item) => {
+ const list2 = item.items;
+ // 每个Category列表下所有的文章,返回的articles里,每个Category为一个数组,底下有N个文章object
+ const articles = Promise.all(
+ list2.map(async (item) => {
+ // 单个Category下单个的文章
+ const iurl = `https://emag-api.hk01.com/v1/articles?articleId=${item.articleId}`;
+ const response3 = await got({
+ method: 'get',
+ url: iurl,
+ headers: {
+ Authorization: hk01Authorization,
+ },
+ });
+ const inner = response3.data.data;
+ const ititle = inner.title[0].content;
+ const istory = inner.story;
+ const icat = inner.categoryName;
+ const issue = inner.journalName;
+ const ilink = `https://ebook.hk01.com/article/${item.articleId}`;
+ const idate = dayjs.utc(item.coverImage.match(/com.([0-9]+)./)[1], 'YYYYMMDD');
+ const icontent = {
+ title: `${issue}|${icat}|${ititle}`,
+ link: ilink,
+ description: istory,
+ pubDate: idate,
+ };
+ return Promise.resolve(icontent);
+ })
+ );
+ return Promise.resolve(articles);
+ })
+ );
+ ctx.cache.set(link, JSON.stringify(single));
+ const list = [];
+ single.forEach((issue) => {
+ issue.forEach((item) => {
+ list.push(item);
+ });
+ });
+
+ ctx.state.data = {
+ title: `《香港01》周報`,
+ link: `https://ebook.hk01.com`,
+
+ item: list.map((item) => ({
+ title: item.title,
+ description: item.description,
+ link: item.link,
+ pubDate: item.pubDate,
+ })),
+ };
+};