From 1acb7e1bf5c1f1d3663aa72448d3a475467aa22a Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 14 Apr 2023 05:47:11 -0700 Subject: [PATCH] feat(arcteryx/outlet): add new route (#12303) --- docs/en/shopping.md | 24 +++++++++++++++++ docs/shopping.md | 24 +++++++++++++++++ lib/v2/arcteryx/maintainer.js | 1 + lib/v2/arcteryx/outlet.js | 51 +++++++++++++++++++++++++++++++++++ lib/v2/arcteryx/radar.js | 8 ++++++ lib/v2/arcteryx/router.js | 1 + 6 files changed, 109 insertions(+) create mode 100644 lib/v2/arcteryx/outlet.js diff --git a/docs/en/shopping.md b/docs/en/shopping.md index fd007d2df..9c6bf7e78 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -62,6 +62,30 @@ Parameter `country` can be found within the url of `Arcteryx` website. +### Outlet + + + +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. + +::: + + + ### Regear New Arrivals diff --git a/docs/shopping.md b/docs/shopping.md index 7b5c9a054..2d82f8572 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -74,6 +74,30 @@ pageClass: routes +### Outlet + + + +国家 + +| 美国 | 加拿大 | 英国 | +| ---- | ------ | ---- | +| us | ca | gb | + +性别 + +| 男 | 女 | +| ---- | ------ | +| mens | womens | + +::: tip 提示 + +参数 `country` 可以在 `Arcteryx` 官网的 URL 中找到。 + +::: + + + ### Regear 新发布 diff --git a/lib/v2/arcteryx/maintainer.js b/lib/v2/arcteryx/maintainer.js index ed0fe6730..bf598fde4 100644 --- a/lib/v2/arcteryx/maintainer.js +++ b/lib/v2/arcteryx/maintainer.js @@ -1,4 +1,5 @@ module.exports = { '/new-arrivals/:country/:gender': ['NavePnow'], + '/outlet/:country/:gender': ['NavePnow'], '/regear/new-arrivals': ['NavePnow'], }; diff --git a/lib/v2/arcteryx/outlet.js b/lib/v2/arcteryx/outlet.js new file mode 100644 index 000000000..8980963c4 --- /dev/null +++ b/lib/v2/arcteryx/outlet.js @@ -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, + }), + })), + }; +}; diff --git a/lib/v2/arcteryx/radar.js b/lib/v2/arcteryx/radar.js index 8f5175755..7f1b9f353 100644 --- a/lib/v2/arcteryx/radar.js +++ b/lib/v2/arcteryx/radar.js @@ -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 新发布', diff --git a/lib/v2/arcteryx/router.js b/lib/v2/arcteryx/router.js index 2ffea3bed..84ac40fcc 100644 --- a/lib/v2/arcteryx/router.js +++ b/lib/v2/arcteryx/router.js @@ -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')); };