feat(route): add ezone.hk (#7121)

* feat: add ezone.hk

* fix typo

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-03-14 01:25:41 -05:00
committed by GitHub
co-authored by NeverBehave
parent 979bac08be
commit bd976fac7e
4 changed files with 88 additions and 0 deletions
+12
View File
@@ -151,6 +151,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
</RouteEn>
## ezone.hk
### Category
<RouteEn author="nczitzk" example="/ezone" path="/ezone/:category?" :paramsDesc="['Category,see below, latest news by default']">
| 科技焦點 | 網絡生活 | 教學評測 | IT Times |
| -------- | -------- | -------- | -------- |
| srae001 | srae008 | srae017 | srae021 |
</RouteEn>
## Google News
### News
+12
View File
@@ -212,6 +212,18 @@ pageClass: routes
<Route author="nczitzk" example="/esquirehk/tag/Fashion" path="/esquirehk/tag/:id" :paramsDesc="['标签,可在对应标签页 URL 中找到']" />
## ezone.hk
### 分类
<Route author="nczitzk" example="/ezone" path="/ezone/:category?" :paramsDesc="['分类,见下表,默认为最新内容']">
| 科技焦點 | 網絡生活 | 教學評測 | IT Times |
| -------- | -------- | -------- | -------- |
| srae001 | srae008 | srae017 | srae021 |
</Route>
## GQ
### GQ 台湾
+3
View File
@@ -4027,6 +4027,9 @@ router.get('/gf-cn/news/:category?', require('./routes/gf-cn/news'));
// Eagle
router.get('/eagle/changelog/:language?', require('./routes/eagle/changelog'));
// ezone.hk
router.get('/ezone/:category?', require('./routes/ezone/index'));
// 中国橡胶网
router.get('/cria/news/:id?', require('./routes/cria/news'));
+61
View File
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category || '';
const rootUrl = 'https://ezone.ulifestyle.com.hk';
const currentUrl = `${rootUrl}/${category || '/getLastestPageRight/latestNews'}`;
const response = await got({
method: 'get',
url: currentUrl,
});
let list = [];
const $ = cheerio.load(response.data);
if (category) {
list = $('.item-grid')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
link: `${rootUrl}${item.attr('href')}`,
};
})
.get();
} else {
list = response.data[0][1].items.map((item) => ({
title: item.headlines.items[0].name,
link: `${rootUrl}/article/${item.standardDocumentId}`,
pubDate: new Date(item.publishDateStr).toUTCString(),
}));
}
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const pubDate = detailResponse.data.match(/<span>(\d{2}-\d{2}-\d{4} \d{2}:\d{2})<\/span>/)[1];
item.title = content('h2').eq(0).text();
item.description = content('.content').html();
item.pubDate = item.pubDate || new Date(`${pubDate.substr(6, 4)}-${pubDate.substr(0, 5)} ${pubDate.substr(11, 5)}`).toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `${category ? $('h1').text() : '最新內容'} - ezone.hk`,
link: category ? currentUrl : rootUrl,
item: items,
};
};