feat(route): add 正版中国 (#9890)
This commit is contained in:
parent
30fafc06ce
commit
78165d77b2
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:category?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -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?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:category?', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue