feat(route): zagg new arrivals (#12059)
* feat(route): zagg new arrivals * Update docs/en/shopping.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * chore: use web api instead * chore: use query instead of params * fix: type * fix: link * Update lib/v2/zagg/new-arrivals.js ---------
This commit is contained in:
parent
fe96ab5620
commit
bbac98491f
|
|
@ -234,3 +234,12 @@ Language
|
|||
### PS5 stock UK
|
||||
|
||||
<RouteEn author="DIYgod" example="/independent/ps5-stock-uk" path="/independent/ps5-stock-uk"/>
|
||||
|
||||
## Zagg
|
||||
|
||||
### New Arrivals
|
||||
|
||||
<RouteEn author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query, search page querystring']"/>
|
||||
|
||||
For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`
|
||||
|
||||
|
|
|
|||
|
|
@ -284,6 +284,14 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
|
|||
|
||||
<Route author="xyqfer" example="/westore/new" path="/westore/new"/>
|
||||
|
||||
## Zagg
|
||||
|
||||
### New Arrivals
|
||||
|
||||
<Route author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query,search page querystring']"/>
|
||||
|
||||
For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`
|
||||
|
||||
## 大麦网
|
||||
|
||||
### 票务更新
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/new-arrivals/:query?': ['NavePnow'],
|
||||
};
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
const got = require('@/utils/got');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const host = 'https://www.zagg.com/en_us';
|
||||
module.exports = async (ctx) => {
|
||||
const query = ctx.params.query;
|
||||
const params = new URLSearchParams(query);
|
||||
const brands = params.get('brand');
|
||||
const categories = params.get('cat');
|
||||
|
||||
const url = `${host}/new-arrivals`;
|
||||
const response = await got({
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
method: 'post',
|
||||
url,
|
||||
searchParams: {
|
||||
cat: categories,
|
||||
brand: brands,
|
||||
},
|
||||
});
|
||||
const products = response.data.products;
|
||||
|
||||
const $ = cheerio.load(products);
|
||||
const list = $('.item.product.product-item')
|
||||
.map(function () {
|
||||
const data = {};
|
||||
const details = $(this).find('.product.details-box').html();
|
||||
data.link = $(this).find('.product-item-link').eq(0).attr('href');
|
||||
data.title = $(this).find('.product-item-link').text();
|
||||
const regex = /(https.*?)\?/;
|
||||
const imgUrl = $(this).find('img').eq(0).attr('data-src').match(regex)[1];
|
||||
const img = art(path.join(__dirname, 'templates/new-arrivals.art'), {
|
||||
imgUrl,
|
||||
});
|
||||
data.description = details + img;
|
||||
return data;
|
||||
})
|
||||
.get();
|
||||
ctx.state.data = {
|
||||
title: 'Zagg - New Arrivals',
|
||||
link: response.url,
|
||||
description: 'Zagg - New Arrivals',
|
||||
item: list.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
link: item.link,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
'zagg.com': {
|
||||
_name: 'New Arrivals',
|
||||
'.': [
|
||||
{
|
||||
title: 'Zagg - New Arrivals',
|
||||
docs: 'https://docs.rsshub.app/shopping.html#zagg',
|
||||
source: ['/en_us/new-arrivals'],
|
||||
target: (_, url) => {
|
||||
const queryString = url.split('?')[1];
|
||||
return `/zagg/new-arrivals/${queryString}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/new-arrivals/:query?', require('./new-arrivals'));
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
<img src={{imgUrl}}>
|
||||
</div>
|
||||
Loading…
Reference in New Issue