feat(route): add patagonia new arrivals (#12060)
* feat(route): add patagonia new arrivals * Update lib/v2/patagonia/new-arrivals.js * fix: description * feat: better image display ---------
This commit is contained in:
parent
197610d147
commit
c3950998a7
|
|
@ -200,6 +200,19 @@ Language
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## Patagonia
|
||||
|
||||
### New Arrivals
|
||||
|
||||
<RouteEn author="NavePnow" example="/patagonia/new-arrivals/mens" path="/patagonia/new-arrivals/:category" :paramsDesc="['category, see below']">
|
||||
|
||||
| Men's | Women's | Kids' & Baby | Packs & Gear |
|
||||
| ----- | ------- | ------------ | ------------ |
|
||||
| mens | womens | kids | luggage |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
|
||||
## ShopBack
|
||||
|
||||
### Store
|
||||
|
|
|
|||
|
|
@ -244,6 +244,18 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
|
|||
|
||||
</Route>
|
||||
|
||||
## Patagonia
|
||||
|
||||
### New Arrivals
|
||||
|
||||
<Route author="NavePnow" example="/patagonia/new-arrivals/mens" path="/patagonia/new-arrivals/:category" :paramsDesc="['分类, 见下表']">
|
||||
|
||||
| Men's | Women's | Kids' & Baby | Packs & Gear |
|
||||
| ----- | ------- | ------------ | ------------ |
|
||||
| mens | womens | kids | luggage |
|
||||
|
||||
</Route>
|
||||
|
||||
## ShopBack
|
||||
|
||||
### Store
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/patagonia/new-arrivals/:category': ['NavePnow'],
|
||||
};
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
const got = require('@/utils/got');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const host = 'https://www.patagonia.com';
|
||||
const categoryMap = {
|
||||
mens: ['mens-new', 'mens-new-arrivals'],
|
||||
womens: ['womens-new', 'womens-new-arrivals'],
|
||||
kids: ['kids-new-arrivals', 'kids-baby-new-arrivals'],
|
||||
luggage: ['luggage-new-arrivals', 'luggage-new-arrivals'],
|
||||
};
|
||||
function extractSfrmUrl(url) {
|
||||
const urlObj = new URL(url);
|
||||
const sfrmValue = urlObj.searchParams.get('sfrm');
|
||||
urlObj.search = new URLSearchParams({ sfrm: sfrmValue }).toString();
|
||||
return urlObj.toString();
|
||||
}
|
||||
module.exports = async (ctx) => {
|
||||
const { category } = ctx.params;
|
||||
const url = `${host}/on/demandware.store/Sites-patagonia-us-Site/en_US/Search-LazyGrid`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
searchParams: {
|
||||
cgid: categoryMap[category][0],
|
||||
isLazyGrid: true,
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.product')
|
||||
.map(function () {
|
||||
const data = {};
|
||||
data.title = $(this).find('.product-tile').data('tealium').product_name[0];
|
||||
let imgUrl = new URL($(this).find('[itemprop="image"]').attr('content'));
|
||||
imgUrl = extractSfrmUrl(imgUrl);
|
||||
|
||||
const price = $(this).find('[itemprop="price"]').eq(0).text();
|
||||
data.link = host + '/' + $(this).find('[itemprop="url"]').attr('href');
|
||||
data.description =
|
||||
price +
|
||||
art(path.join(__dirname, 'templates/product-description.art'), {
|
||||
imgUrl,
|
||||
});
|
||||
data.category = $(this).find('[itemprop="category"]').attr('content');
|
||||
return data;
|
||||
})
|
||||
.get();
|
||||
ctx.state.data = {
|
||||
title: `Patagonia - New Arrivals - ${category.toUpperCase()}`,
|
||||
link: `${host}/shop/${categoryMap[category][1]}`,
|
||||
description: `Patagonia - New Arrivals - ${category.toUpperCase()}`,
|
||||
item: list.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
link: item.link,
|
||||
category: item.category,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
module.exports = {
|
||||
'patagonia.com': {
|
||||
_name: 'Patagonia',
|
||||
'.': [
|
||||
{
|
||||
title: 'New Arrivals',
|
||||
docs: 'https://docs.rsshub.app/shopping.html#patagonia',
|
||||
source: ['/shop/*new-arrivals'],
|
||||
target: (_, url) => {
|
||||
const param = new URL(url).pathname.split('/').pop().replace('-new-arrivals', '');
|
||||
if (param === 'new-arrivals') {
|
||||
return '';
|
||||
}
|
||||
if (param === 'kids-baby') {
|
||||
return '/patagonia/new-arrivals/kids';
|
||||
} else {
|
||||
return `/patagonia/new-arrivals/${param}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/new-arrivals/:category', require('./new-arrivals'));
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<img src={{imgUrl}}>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue