forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add patagonia new arrivals (DIYgod#12060)
* feat(route): add patagonia new arrivals * Update lib/v2/patagonia/new-arrivals.js * fix: description * feat: better image display ---------
- Loading branch information
1 parent
197610d
commit c395099
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/patagonia/new-arrivals/:category': ['NavePnow'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
})), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`; | ||
} | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/new-arrivals/:category', require('./new-arrivals')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
<img src={{imgUrl}}> | ||
</div> | ||
|