From afa8676c7d7690b17d21e2ac7aad55861eb9cbae Mon Sep 17 00:00:00 2001 From: hoilc Date: Tue, 22 Oct 2019 11:28:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=A6=99=E6=B8=AF01?= =?UTF-8?q?=20(#3300)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add hk01 * remove image proxy --- docs/traditional-media.md | 22 ++++++++++++++++++++ lib/router.js | 7 +++++++ lib/routes/hk01/channel.js | 22 ++++++++++++++++++++ lib/routes/hk01/hot.js | 20 +++++++++++++++++++ lib/routes/hk01/issue.js | 22 ++++++++++++++++++++ lib/routes/hk01/tag.js | 22 ++++++++++++++++++++ lib/routes/hk01/zone.js | 41 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 156 insertions(+) create mode 100644 lib/routes/hk01/channel.js create mode 100644 lib/routes/hk01/hot.js create mode 100644 lib/routes/hk01/issue.js create mode 100644 lib/routes/hk01/tag.js create mode 100644 lib/routes/hk01/zone.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 198cb57da..2791b13a1 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -302,6 +302,28 @@ category 对应的关键词有 +## 香港 01 + +### 热门 + + + +### 栏目 + + + +### 子栏目 + + + +### 专题 + + + +### 标签 + + + ## 新京报 ### 栏目 diff --git a/lib/router.js b/lib/router.js index ba2e64359..e810d3b66 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1874,6 +1874,13 @@ router.get('/mcbbs/post/:tid/:authorid?', require('./routes/mcbbs/post')); // Pocket router.get('/pocket/trending', require('./routes/pocket/trending')); +// HK01 +router.get('/hk01/zone/:id', require('./routes/hk01/zone')); +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('/manong-weekly', require('./routes/manong-weekly/issues')); diff --git a/lib/routes/hk01/channel.js b/lib/routes/hk01/channel.js new file mode 100644 index 000000000..253e10c2d --- /dev/null +++ b/lib/routes/hk01/channel.js @@ -0,0 +1,22 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got(`https://web-data.api.hk01.com/v2/page/category/${id}`); + const data = response.data; + const list = data.sections[0].items; + + ctx.state.data = { + title: `香港01 - ${data.category.publishName}`, + description: data.meta.metaDesc, + link: data.category.publishUrl, + item: list.map((item) => ({ + title: item.data.title, + author: item.data.authors.map((e) => e.publishName).join(', '), + description: `

${item.data.description}…

`, + pubDate: new Date(item.data.lastModifyTime * 1000), + link: item.data.canonicalUrl, + })), + }; +}; diff --git a/lib/routes/hk01/hot.js b/lib/routes/hk01/hot.js new file mode 100644 index 000000000..944966771 --- /dev/null +++ b/lib/routes/hk01/hot.js @@ -0,0 +1,20 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got('https://web-data.api.hk01.com/v2/page/hot/'); + const data = response.data; + const list = data.items; + + ctx.state.data = { + title: '香港01 - 熱門', + description: data.meta.metaDesc, + link: data.meta.canonicalUrl, + item: list.map((item) => ({ + title: item.data.title, + author: item.data.authors.map((e) => e.publishName).join(', '), + description: `

${item.data.description}

`, + pubDate: new Date(item.data.lastModifyTime * 1000), + link: item.data.canonicalUrl, + })), + }; +}; diff --git a/lib/routes/hk01/issue.js b/lib/routes/hk01/issue.js new file mode 100644 index 000000000..1f079faf3 --- /dev/null +++ b/lib/routes/hk01/issue.js @@ -0,0 +1,22 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got(`https://web-data.api.hk01.com/v2/page/issue/${id}`); + const data = response.data; + const list = data.issue.blocks[0].articles; + + ctx.state.data = { + title: `香港01 - ${data.issue.title}`, + description: data.meta.metaDesc, + link: data.issue.publishUrl, + item: list.map((item) => ({ + title: item.data.title, + author: item.data.authors.map((e) => e.publishName).join(', '), + description: `

${item.data.description}…

`, + pubDate: new Date(item.data.lastModifyTime * 1000), + link: item.data.canonicalUrl, + })), + }; +}; diff --git a/lib/routes/hk01/tag.js b/lib/routes/hk01/tag.js new file mode 100644 index 000000000..54691c952 --- /dev/null +++ b/lib/routes/hk01/tag.js @@ -0,0 +1,22 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got(`https://web-data.api.hk01.com/v2/page/tag/${id}`); + const data = response.data; + const list = data.articles; + + ctx.state.data = { + title: `香港01 - ${data.tag.tagName}`, + description: data.meta.metaDesc, + link: data.tag.publishUrl, + item: list.map((item) => ({ + title: item.data.title, + author: item.data.authors.map((e) => e.publishName).join(', '), + description: `

${item.data.description}

`, + pubDate: new Date(item.data.lastModifyTime * 1000), + link: item.data.canonicalUrl, + })), + }; +}; diff --git a/lib/routes/hk01/zone.js b/lib/routes/hk01/zone.js new file mode 100644 index 000000000..3131d8584 --- /dev/null +++ b/lib/routes/hk01/zone.js @@ -0,0 +1,41 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got(`https://web-data.api.hk01.com/v2/page/zone/${id}`); + const data = response.data; + const list = data.sections[0].items; + + ctx.state.data = { + title: `香港01 - ${data.zone.publishName}`, + description: data.meta.metaDesc, + link: data.zone.publishUrl, + item: list.map((item) => { + let author; + let description; + let pubDate; + switch (item.type) { + case 1: + author = item.data.authors.map((e) => e.publishName).join(', '); + description = `

${item.data.description}

`; + pubDate = new Date(item.data.lastModifyTime * 1000); + break; + case 2: + author = item.data.zonePublishName; + description = `${item.data.teaser.map((e) => '

' + e + '

').join('')}`; + pubDate = new Date(); + break; + default: + break; + } + return { + title: item.data.title, + author: author, + description: description, + pubDate: pubDate, + link: item.data.canonicalUrl, + }; + }), + }; +};