Skip to content

Commit

Permalink
feat(route): arcteryx regear new arrivals (DIYgod#12063)
Browse files Browse the repository at this point in the history
* feat(route): arcteryx regear new arrivals

* feat(route): arcteryx regear new arrivals

* Update lib/v2/arcteryx/radar.js

* fix: arcteryx regear radar

* fix: arcteryx regear price

* fix: filter first

---------
  • Loading branch information
EthanWng97 authored Mar 8, 2023
1 parent c395099 commit 965e652
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/en/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Parameter `country` can be found within the url of `Arcteryx` website.

</RouteEn>

### Regear New Arrivals

<RouteEn author="NavePnow" example="/arcteryx/regear/new-arrivals" path="/arcteryx/regear/new-arrivals" />

## Bellroy

### New Releases
Expand Down
4 changes: 4 additions & 0 deletions docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pageClass: routes

</Route>

### Regear 新发布

<Route author="NavePnow" example="/arcteryx/regear/new-arrivals" path="/arcteryx/regear/new-arrivals" />

## Bellroy

### 新发布
Expand Down
1 change: 1 addition & 0 deletions lib/v2/arcteryx/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/new-arrivals/:country/:gender': ['NavePnow'],
'/regear/new-arrivals': ['NavePnow'],
};
8 changes: 8 additions & 0 deletions lib/v2/arcteryx/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ module.exports = {
target: '/arcteryx/new-arrivals/:country/:gender',
},
],
regear: [
{
title: 'Regear 新发布',
docs: 'https://docs.rsshub.app/shopping.html#arcteryx',
source: ['/shop/new-arrivals', '/'],
target: '/arcteryx/regear/new-arrivals',
},
],
},
};
53 changes: 53 additions & 0 deletions lib/v2/arcteryx/regear-new-arrivals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { art } = require('@/utils/render');
const path = require('path');

const host = 'https://www.regear.arcteryx.com';
function getUSDPrice(number) {
return (number / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
module.exports = async (ctx) => {
const url = `${host}/shop/new-arrivals`;
const response = await got({
method: 'get',
url,
});

const data = response.data;
const $ = cheerio.load(data);
const contents = $('script:contains("window.__PRELOADED_STATE__")').text();
const regex = /{.*}/;
let items = JSON.parse(contents.match(regex)[0]).shop.items;
items = items.filter((item) => item.availableSizes.length !== 0);

const list = items.map((item) => {
const data = {};
data.title = item.displayTitle;
data.link = item.pdpLink.url;
data.imgUrl = JSON.parse(item.imageUrls).front;
data.availableSizes = item.availableSizes;
data.color = item.color;
data.originalPrice = getUSDPrice(item.originalPrice);
if (item.priceRange[0] === item.priceRange[1]) {
data.regearPrice = getUSDPrice(item.priceRange[0]);
} else {
data.regearPrice = `${getUSDPrice(item.priceRange[0])} - ${getUSDPrice(item.priceRange[1])}`;
}
data.description = art(path.join(__dirname, 'templates/regear-product-description.art'), {
data,
});
return data;
});

ctx.state.data = {
title: 'Arcteryx - Regear - New Arrivals',
link: url,
description: 'Arcteryx - Regear - New Arrivals',
item: list.map((item) => ({
title: item.title,
link: item.link,
description: item.description,
})),
};
};
1 change: 1 addition & 0 deletions lib/v2/arcteryx/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/new-arrivals/:country/:gender', require('./new-arrivals'));
router.get('/regear/new-arrivals', require('./regear-new-arrivals'));
};
16 changes: 16 additions & 0 deletions lib/v2/arcteryx/templates/regear-product-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div>
Available Sizes:&nbsp;
{{each data.availableSizes}}
{{$value}}&nbsp;
{{/each}}
<br>
Color: {{data.color}}
<br>
Original Price: {{data.originalPrice}}
<br>
Regear Price: {{data.regearPrice}}
<br>

<img src={{data.imgUrl}}>
<br><br>
</div>

0 comments on commit 965e652

Please sign in to comment.