feat(route): add 正版中国 (#9890)

This commit is contained in:
Ethan Shen 2022-06-04 12:08:36 +08:00 committed by GitHub
parent 30fafc06ce
commit 78165d77b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 0 deletions

View File

@ -431,3 +431,15 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
### 商品上新
<Route author="LogicJake" example="/youzan/goods/13328377" path="/youzan/goods/:id" :paramsDesc="['商铺id']"/>
## 正版中国
### 分类
<Route author="nczitzk" example="/getitfree" path="/getitfree/:category?" :paramsDesc="['分类,见下表,默认为所有类别']">
| 所有类别 | Android | iOS | Mac | PC | UWP | 公告 | 永久免费 | 限时免费 | 限时折扣 |
| ---- | ------- | --- | --- | -- | --- | ------------ | ---- | -------- | -------- |
| | android | ios | mac | pc | uwp | notification | free | giveaway | discount |
</Route>

54
lib/v2/getitfree/index.js Normal file
View File

@ -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,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};

13
lib/v2/getitfree/radar.js Normal file
View File

@ -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?',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./index'));
};