diff --git a/docs/en/new-media.md b/docs/en/new-media.md index 9aa969c501..0ec3cbbc48 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -151,6 +151,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## ezone.hk + +### Category + + + +| 科技焦點 | 網絡生活 | 教學評測 | IT Times | +| -------- | -------- | -------- | -------- | +| srae001 | srae008 | srae017 | srae021 | + + + ## Google News ### News diff --git a/docs/new-media.md b/docs/new-media.md index 6adcd411b0..3aa64122b3 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -212,6 +212,18 @@ pageClass: routes +## ezone.hk + +### 分类 + + + +| 科技焦點 | 網絡生活 | 教學評測 | IT Times | +| -------- | -------- | -------- | -------- | +| srae001 | srae008 | srae017 | srae021 | + + + ## GQ ### GQ 台湾 diff --git a/lib/router.js b/lib/router.js index 15ff08f517..db4df8d206 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/ezone/index.js b/lib/routes/ezone/index.js new file mode 100644 index 0000000000..0f7beb523b --- /dev/null +++ b/lib/routes/ezone/index.js @@ -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(/(\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, + }; +};