Skip to content

Commit

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

* fix: radar source

---------
  • Loading branch information
EthanWng97 authored Mar 5, 2023
1 parent 7035c39 commit 9498669
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/en/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ Parameter `time` only works when `mostwanted` is chosen as the category.

</RouteEn>

## Arcteryx

### New Arrivals

<RouteEn author="NavePnow" example="/arcteryx/new-arrivals/us/mens" path="/arcteryx/new-arrivals/: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>

## Bellroy

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

</Route>

## Arcteryx

### 新发布

<Route author="NavePnow" example="/arcteryx/new-arrivals/us/mens" path="/arcteryx/new-arrivals/:country/:gender" :paramsDesc="['国家', '性别']">

国家

| 美国 | 加拿大 | 英国 |
| -- | --- | -- |
| us | ca | gb |

性别

|||
| ---- | ------ |
| mens | womens |

::: tip 提示

参数 `country` 可以在 `Arcteryx` 官网的 URL 中找到。

:::

</Route>

## Bellroy

### 新发布
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/arcteryx/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/new-arrivals/:country/:gender': ['NavePnow'],
};
49 changes: 49 additions & 0 deletions lib/v2/arcteryx/new-arrivals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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://arcteryx.com/${country}/en/`;
const url = `${host}api/fredhopper/query`;
const productUrl = `${host}shop/`;
const pageUrl = `${host}c/${gender}/new-arrivals`;
const response = await got({
method: 'get',
url,
searchParams: {
fh_location: `//catalog01/en_CA/gender>{${gender}}/intended_use>{newarrivals}`,
fh_country: country,
fh_view_size: 'all',
},
});
const items = response.data.universes.universe[1]['items-section'].items.item;
items.forEach(generateRssData);

ctx.state.data = {
title: `Arcteryx - New Arrivals(${country.toUpperCase()}) - ${gender.toUpperCase()}`,
link: pageUrl,
description: `Arcteryx - New Arrivals(${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,
}),
})),
};
};
13 changes: 13 additions & 0 deletions lib/v2/arcteryx/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'arcteryx.com': {
_name: 'Arcteryx',
'.': [
{
title: '新发布',
docs: 'https://docs.rsshub.app/shopping.html#arcteryx',
source: ['/:country/en/c/:gender/new-arrivals'],
target: '/arcteryx/new-arrivals/:country/:gender',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/arcteryx/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/new-arrivals/:country/:gender', require('./new-arrivals'));
};
6 changes: 6 additions & 0 deletions lib/v2/arcteryx/templates/product-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<img src={{item.image}}>
<br><br>
{{item.short_description}}
<br><br>
</div>

0 comments on commit 9498669

Please sign in to comment.