diff --git a/docs/new-media.md b/docs/new-media.md index a9b2f164d..b8b68434d 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2116,3 +2116,15 @@ QueryString: ### 全文 + +## 眾新聞 + +### 眾聞 + + + +| 全部 | 經濟 | 社會 | 生活 | 政治 | 國際 | 台灣 | 人物 | 中國 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| | 13 | 15 | 14 | 12 | 16 | 20 | 21 | 19 | + + diff --git a/lib/router.js b/lib/router.js index 84224d5f9..aac79523e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3789,6 +3789,9 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); +// 眾新聞 +router.get('/hkcnews/news/:category?', require('./routes/hkcnews/news')); + // AnyTXT router.get('/anytxt/release-notes', require('./routes/anytxt/release-notes')); @@ -3826,4 +3829,5 @@ router.get('/rfa/:language?/:channel?/:subChannel?', require('./routes/rfa/index // booth.pm router.get('/booth.pm/shop/:subdomain', require('./routes/booth-pm/shop')); + module.exports = router; diff --git a/lib/routes/hkcnews/news.js b/lib/routes/hkcnews/news.js new file mode 100644 index 000000000..1c040d854 --- /dev/null +++ b/lib/routes/hkcnews/news.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const titles = { + '': '眾聞', + 13: '經濟', + 15: '社會', + 14: '生活', + 12: '政治', + 16: '國際', + 20: '台灣', + 21: '人物', + 19: '中國', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category || ''; + + const rootUrl = 'https://www.hkcnews.com'; + const apiUrl = `${rootUrl}/data/newsposts${category === '' ? '' : `/${category}`}?page=1`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const list = response.data.items.map((item) => { + const $ = cheerio.load(item); + const news = $('.article-block-body a'); + const date = $('.line').eq(1).text().split('.').reverse().join('-'); + + return { + title: news.text(), + link: `${rootUrl}/${news.attr('href')}`, + pubDate: new Date(date.length === 8 ? `${new Date().getFullYear().toString().slice(0, 2)}${date}` : date).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); + + item.description = content('.article-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `眾新聞 - ${titles[category]}`, + link: `${rootUrl}/news${category === '' ? '' : `/${category}/${titles[category]}`}`, + item: items, + }; +};