Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): arcteryx regear new arrivals #12063

Merged
merged 6 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>