forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add ezone.hk (DIYgod#7121)
* feat: add ezone.hk * fix typo Co-authored-by: NeverBehave <[email protected]>
- Loading branch information
1 parent
979bac0
commit bd976fa
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |