Skip to content

Commit bbac984

Browse files
author
Evan
authored
feat(route): zagg new arrivals (DIYgod#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 ---------
1 parent fe96ab5 commit bbac984

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

docs/en/shopping.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,12 @@ Language
234234
### PS5 stock UK
235235

236236
<RouteEn author="DIYgod" example="/independent/ps5-stock-uk" path="/independent/ps5-stock-uk"/>
237+
238+
## Zagg
239+
240+
### New Arrivals
241+
242+
<RouteEn author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query, search page querystring']"/>
243+
244+
For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`
245+

docs/shopping.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
284284

285285
<Route author="xyqfer" example="/westore/new" path="/westore/new"/>
286286

287+
## Zagg
288+
289+
### New Arrivals
290+
291+
<Route author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query,search page querystring']"/>
292+
293+
For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`
294+
287295
## 大麦网
288296

289297
### 票务更新

lib/v2/zagg/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/new-arrivals/:query?': ['NavePnow'],
3+
};

lib/v2/zagg/new-arrivals.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const got = require('@/utils/got');
2+
const { art } = require('@/utils/render');
3+
const path = require('path');
4+
const cheerio = require('cheerio');
5+
const host = 'https://www.zagg.com/en_us';
6+
module.exports = async (ctx) => {
7+
const query = ctx.params.query;
8+
const params = new URLSearchParams(query);
9+
const brands = params.get('brand');
10+
const categories = params.get('cat');
11+
12+
const url = `${host}/new-arrivals`;
13+
const response = await got({
14+
headers: {
15+
'X-Requested-With': 'XMLHttpRequest',
16+
},
17+
method: 'post',
18+
url,
19+
searchParams: {
20+
cat: categories,
21+
brand: brands,
22+
},
23+
});
24+
const products = response.data.products;
25+
26+
const $ = cheerio.load(products);
27+
const list = $('.item.product.product-item')
28+
.map(function () {
29+
const data = {};
30+
const details = $(this).find('.product.details-box').html();
31+
data.link = $(this).find('.product-item-link').eq(0).attr('href');
32+
data.title = $(this).find('.product-item-link').text();
33+
const regex = /(https.*?)\?/;
34+
const imgUrl = $(this).find('img').eq(0).attr('data-src').match(regex)[1];
35+
const img = art(path.join(__dirname, 'templates/new-arrivals.art'), {
36+
imgUrl,
37+
});
38+
data.description = details + img;
39+
return data;
40+
})
41+
.get();
42+
ctx.state.data = {
43+
title: 'Zagg - New Arrivals',
44+
link: response.url,
45+
description: 'Zagg - New Arrivals',
46+
item: list.map((item) => ({
47+
title: item.title,
48+
description: item.description,
49+
link: item.link,
50+
})),
51+
};
52+
};

lib/v2/zagg/radar.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
'zagg.com': {
3+
_name: 'New Arrivals',
4+
'.': [
5+
{
6+
title: 'Zagg - New Arrivals',
7+
docs: 'https://docs.rsshub.app/shopping.html#zagg',
8+
source: ['/en_us/new-arrivals'],
9+
target: (_, url) => {
10+
const queryString = url.split('?')[1];
11+
return `/zagg/new-arrivals/${queryString}`;
12+
},
13+
},
14+
],
15+
},
16+
};

lib/v2/zagg/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function (router) {
2+
router.get('/new-arrivals/:query?', require('./new-arrivals'));
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<img src={{imgUrl}}>
3+
</div>

0 commit comments

Comments
 (0)