diff --git a/lib/v2/consumer/maintainer.js b/lib/v2/consumer/maintainer.js index 8b9d4047f9..a490a0e855 100644 --- a/lib/v2/consumer/maintainer.js +++ b/lib/v2/consumer/maintainer.js @@ -1,3 +1,4 @@ module.exports = { + '/shopping-guide/:category?/:language?': ['TonyRL'], '/:category?/:language?/:keyword?': ['nczitzk'], }; diff --git a/lib/v2/consumer/radar.js b/lib/v2/consumer/radar.js index 124f1dd894..a43c3a8af6 100644 --- a/lib/v2/consumer/radar.js +++ b/lib/v2/consumer/radar.js @@ -8,6 +8,12 @@ module.exports = { source: ['/'], target: '/consumer/:category?/:language?/:keyword?', }, + { + title: '消費全攻略', + docs: 'https://docs.rsshub.app/routes/new-media#xiao-fei-zhe-wei-yuan-hui', + source: ['/:language/shopping-guide/:category'], + target: '/consumer/shopping-guide/:category/:language', + }, ], }, }; diff --git a/lib/v2/consumer/router.js b/lib/v2/consumer/router.js index fe6b14f1bf..f8abac22c6 100644 --- a/lib/v2/consumer/router.js +++ b/lib/v2/consumer/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { + router.get('/shopping-guide/:category?/:language?', require('./shopping-guide')); router.get('/:category?/:language?/:keyword?', require('./index')); }; diff --git a/lib/v2/consumer/shopping-guide.js b/lib/v2/consumer/shopping-guide.js new file mode 100644 index 0000000000..ccb76e6549 --- /dev/null +++ b/lib/v2/consumer/shopping-guide.js @@ -0,0 +1,66 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category = 'trivia', language = 'tc' } = ctx.params; + const rootUrl = 'https://www.consumer.org.hk'; + const currentUrl = `${rootUrl}/${language}/shopping-guide/${category}`; + + const { data: response } = await got(currentUrl, { + headers: { + cookie: `consumer_pagination={${encodeURI('"228c"')}:24}`, + }, + }); + + const $ = cheerio.load(response); + + const list = $('.shadow-long-blk') + .toArray() + .map((item) => { + item = $(item); + + const info = item + .find('.item-info li') + .toArray() + .map((item) => $(item).text().trim()); + return { + title: item.find('h2').text().trim(), + description: item.find('p').text().trim(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(info.shift(), 'YYYY-MM-DD'), + category: info, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + const header = $('.article-img-blk'); + header.find('img').each((_, ele) => { + ele = $(ele); + if (ele.attr('src') && ele.attr('srcset')) { + ele.removeAttr('srcset'); + ele.attr('src', ele.attr('src').replace(/\/\d+c\d+\//, '/0p0/')); + } + }); + + item.description = header.html() + $('article .ckec').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link: currentUrl, + image: $('meta[property="og:image"]').attr('content'), + logo: $('link[rel="apple-touch-icon"]').attr('href'), + icon: $('link[rel="apple-touch-icon"]').attr('href'), + item: items, + }; +}; diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx index e2ef61bb66..49ae0b4408 100644 --- a/website/docs/routes/new-media.mdx +++ b/website/docs/routes/new-media.mdx @@ -4698,6 +4698,14 @@ | sc | tc | +### 消費全攻略 {#xiao-fei-zhe-wei-yuan-hui-xiao-fei-quan-gong-lve} + + + | 冷知識 | 懶人包 | 特集 | 銀髮一族 | 飲食煮意 | 科技達人 | 健康美容 | 規劃人生 | 消閒娛樂 | 家品家電 | 親子時光 | 綠色生活 | + | ------ | ------ | -------- | ------------------ | ---------------- | ---------- | ----------------- | --------------------------- | ------------------------- | --------------- | --------------- | ------------ | + | trivia | tips | features | silver-hair-market | food-and-cooking | tech-savvy | health-and-beauty | life-and-financial-planning | leisure-and-entertainment | home-appliances | family-and-kids | green-living | + + ## 小刀娱乐网 {#xiao-dao-yu-le-wang} ### 分类 {#xiao-dao-yu-le-wang-fen-lei}