feat(arcteryx/outlet): add new route (#12303)

This commit is contained in:
Evan 2023-04-14 05:47:11 -07:00 committed by GitHub
parent 0d60360cdd
commit 1acb7e1bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 0 deletions

View File

@ -62,6 +62,30 @@ Parameter `country` can be found within the url of `Arcteryx` website.
</RouteEn>
### Outlet
<RouteEn author="NavePnow" example="/arcteryx/outlet/us/mens" path="/arcteryx/outlet/:country/:gender" :paramsDesc="['country', 'gender']">
Country
| United States | Canada | United Kingdom |
| ------------- | ------ | -------------- |
| us | ca | gb |
gender
| male | female |
| ---- | ------ |
| mens | womens |
::: tip
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" />

View File

@ -74,6 +74,30 @@ pageClass: routes
</Route>
### Outlet
<Route author="NavePnow" example="/arcteryx/outlet/us/mens" path="/arcteryx/outlet/:country/:gender" :paramsDesc="['国家', '性别']">
国家
| 美国 | 加拿大 | 英国 |
| ---- | ------ | ---- |
| us | ca | gb |
性别
| 男 | 女 |
| ---- | ------ |
| mens | womens |
::: tip 提示
参数 `country` 可以在 `Arcteryx` 官网的 URL 中找到。
:::
</Route>
### Regear 新发布
<Route author="NavePnow" example="/arcteryx/regear/new-arrivals" path="/arcteryx/regear/new-arrivals" />

View File

@ -1,4 +1,5 @@
module.exports = {
'/new-arrivals/:country/:gender': ['NavePnow'],
'/outlet/:country/:gender': ['NavePnow'],
'/regear/new-arrivals': ['NavePnow'],
};

51
lib/v2/arcteryx/outlet.js Normal file
View File

@ -0,0 +1,51 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const attributeSet = new Set(['name', 'image', 'short_description', 'slug']);
function generateRssData(item, index, arr) {
const attributes = item.attribute;
const data = {};
attributes.forEach((attribute) => {
const key = attribute.name;
const value = attribute.value[0].value;
if (attributeSet.has(key)) {
data[key] = value;
}
});
arr[index] = data;
}
module.exports = async (ctx) => {
const { country, gender } = ctx.params;
const host = `https://outlet.arcteryx.com/${country}/en/`;
const url = `${host}api/fredhopper/query`;
const productUrl = `${host}shop/`;
const pageUrl = `${host}c/${gender}`;
const response = await got({
method: 'get',
url,
searchParams: {
fh_location: `//catalog01/en_CA/gender>{${gender}}`,
fh_country: country,
fh_review: 'lister',
fh_view_size: 'all',
fh_context_location: '//catalog01',
},
});
const items = response.data.universes.universe[1]['items-section'].items.item;
items.forEach(generateRssData);
ctx.state.data = {
title: `Arcteryx - Outlet(${country.toUpperCase()}) - ${gender.toUpperCase()}`,
link: pageUrl,
description: `Arcteryx - Outlet(${country.toUpperCase()}) - ${gender.toUpperCase()}`,
item: items.map((item) => ({
title: item.name,
link: productUrl + item.slug,
description: art(path.join(__dirname, 'templates/product-description.art'), {
item,
}),
})),
};
};

View File

@ -9,6 +9,14 @@ module.exports = {
target: '/arcteryx/new-arrivals/:country/:gender',
},
],
outlet: [
{
title: 'Outlet',
docs: 'https://docs.rsshub.app/shopping.html#arcteryx',
source: ['/:country/en/c/:gender'],
target: '/arcteryx/outlet/:country/:gender',
},
],
regear: [
{
title: 'Regear 新发布',

View File

@ -1,4 +1,5 @@
module.exports = function (router) {
router.get('/new-arrivals/:country/:gender', require('./new-arrivals'));
router.get('/outlet/:country/:gender', require('./outlet'));
router.get('/regear/new-arrivals', require('./regear-new-arrivals'));
};