Skip to content

Commit

Permalink
feat(route): add ezone.hk (DIYgod#7121)
Browse files Browse the repository at this point in the history
* feat: add ezone.hk

* fix typo

Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Mar 14, 2021
1 parent 979bac0 commit bd976fa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/en/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 台湾
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
61 changes: 61 additions & 0 deletions lib/routes/ezone/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit bd976fa

Please sign in to comment.