feat: 添加香港01 (#3300)

* add hk01

* remove image proxy
This commit is contained in:
hoilc
2019-10-22 11:28:04 +08:00
committed by DIYgod
parent 6df530f946
commit afa8676c7d
7 changed files with 156 additions and 0 deletions

View File

@@ -302,6 +302,28 @@ category 对应的关键词有
<Route author="Polynomia" example="/guardian/china" path="/guardian/china"/> <Route author="Polynomia" example="/guardian/china" path="/guardian/china"/>
## 香港 01
### 热门
<Route author="hoilc" example="/hk01/hot" path="/hk01/hot" />
### 栏目
<Route author="hoilc" example="/hk01/zone/11" path="/hk01/zone/:id" :paramsDesc="['栏目id, 可在URL中找到']"/>
### 子栏目
<Route author="hoilc" example="/hk01/channel/391" path="/hk01/channel/:id" :paramsDesc="['子栏目id, 可在URL中找到']"/>
### 专题
<Route author="hoilc" example="/hk01/issue/649" path="/hk01/issue/:id" :paramsDesc="['专题id, 可在URL中找到']"/>
### 标签
<Route author="hoilc" example="/hk01/tag/2787" path="/hk01/tag/:id" :paramsDesc="['标签id, 可在URL中找到']"/>
## 新京报 ## 新京报
### 栏目 ### 栏目

View File

@@ -1874,6 +1874,13 @@ router.get('/mcbbs/post/:tid/:authorid?', require('./routes/mcbbs/post'));
// Pocket // Pocket
router.get('/pocket/trending', require('./routes/pocket/trending')); 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')); router.get('/manong-weekly', require('./routes/manong-weekly/issues'));

View File

@@ -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: `<p>${item.data.description}…</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
pubDate: new Date(item.data.lastModifyTime * 1000),
link: item.data.canonicalUrl,
})),
};
};

20
lib/routes/hk01/hot.js Normal file
View File

@@ -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: `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
pubDate: new Date(item.data.lastModifyTime * 1000),
link: item.data.canonicalUrl,
})),
};
};

22
lib/routes/hk01/issue.js Normal file
View File

@@ -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: `<p>${item.data.description}…</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
pubDate: new Date(item.data.lastModifyTime * 1000),
link: item.data.canonicalUrl,
})),
};
};

22
lib/routes/hk01/tag.js Normal file
View File

@@ -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: `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`,
pubDate: new Date(item.data.lastModifyTime * 1000),
link: item.data.canonicalUrl,
})),
};
};

41
lib/routes/hk01/zone.js Normal file
View File

@@ -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 = `<p>${item.data.description}</p><img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`;
pubDate = new Date(item.data.lastModifyTime * 1000);
break;
case 2:
author = item.data.zonePublishName;
description = `${item.data.teaser.map((e) => '<p>' + e + '</p>').join('')}<img style="width: 100%" src="${item.data.mainImage.cdnUrl}" />`;
pubDate = new Date();
break;
default:
break;
}
return {
title: item.data.title,
author: author,
description: description,
pubDate: pubDate,
link: item.data.canonicalUrl,
};
}),
};
};