diff --git a/docs/shopping.md b/docs/shopping.md index 4e4a20b70..ec5a5b314 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -431,3 +431,15 @@ For instance, in + +## 正版中国 + +### 分类 + + + +| 所有类别 | Android | iOS | Mac | PC | UWP | 公告 | 永久免费 | 限时免费 | 限时折扣 | +| ---- | ------- | --- | --- | -- | --- | ------------ | ---- | -------- | -------- | +| | android | ios | mac | pc | uwp | notification | free | giveaway | discount | + + diff --git a/lib/v2/getitfree/index.js b/lib/v2/getitfree/index.js new file mode 100644 index 000000000..9d9bd971e --- /dev/null +++ b/lib/v2/getitfree/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? ''; + + const rootUrl = 'https://www.getitfree.cn'; + const currentUrl = `${rootUrl}${category ? `/category/${category}` : ''}/page/1`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('a.post-title') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('h3, footer').remove(); + + item.description = content('.post-content-text').html(); + item.pubDate = parseDate(content('time.entry-date').first().attr('datetime')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/getitfree/maintainer.js b/lib/v2/getitfree/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/getitfree/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/getitfree/radar.js b/lib/v2/getitfree/radar.js new file mode 100644 index 000000000..8989af49f --- /dev/null +++ b/lib/v2/getitfree/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'getitfree.cn': { + _name: '正版中国', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/shopping.html#zheng-ban-zhong-guo-fen-lei', + source: ['/category/:category', '/'], + target: '/getitfree/:category?', + }, + ], + }, +}; diff --git a/lib/v2/getitfree/router.js b/lib/v2/getitfree/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/getitfree/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +};