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): arcteryx regear new arrivals (DIYgod#12063)
* feat(route): arcteryx regear new arrivals * feat(route): arcteryx regear new arrivals * Update lib/v2/arcteryx/radar.js * fix: arcteryx regear radar * fix: arcteryx regear price * fix: filter first ---------
- Loading branch information
1 parent
c395099
commit 965e652
Showing
7 changed files
with
87 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/new-arrivals/:country/:gender': ['NavePnow'], | ||
'/regear/new-arrivals': ['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
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,53 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
|
||
const host = 'https://www.regear.arcteryx.com'; | ||
function getUSDPrice(number) { | ||
return (number / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' }); | ||
} | ||
module.exports = async (ctx) => { | ||
const url = `${host}/shop/new-arrivals`; | ||
const response = await got({ | ||
method: 'get', | ||
url, | ||
}); | ||
|
||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
const contents = $('script:contains("window.__PRELOADED_STATE__")').text(); | ||
const regex = /{.*}/; | ||
let items = JSON.parse(contents.match(regex)[0]).shop.items; | ||
items = items.filter((item) => item.availableSizes.length !== 0); | ||
|
||
const list = items.map((item) => { | ||
const data = {}; | ||
data.title = item.displayTitle; | ||
data.link = item.pdpLink.url; | ||
data.imgUrl = JSON.parse(item.imageUrls).front; | ||
data.availableSizes = item.availableSizes; | ||
data.color = item.color; | ||
data.originalPrice = getUSDPrice(item.originalPrice); | ||
if (item.priceRange[0] === item.priceRange[1]) { | ||
data.regearPrice = getUSDPrice(item.priceRange[0]); | ||
} else { | ||
data.regearPrice = `${getUSDPrice(item.priceRange[0])} - ${getUSDPrice(item.priceRange[1])}`; | ||
} | ||
data.description = art(path.join(__dirname, 'templates/regear-product-description.art'), { | ||
data, | ||
}); | ||
return data; | ||
}); | ||
|
||
ctx.state.data = { | ||
title: 'Arcteryx - Regear - New Arrivals', | ||
link: url, | ||
description: 'Arcteryx - Regear - New Arrivals', | ||
item: list.map((item) => ({ | ||
title: item.title, | ||
link: item.link, | ||
description: item.description, | ||
})), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = function (router) { | ||
router.get('/new-arrivals/:country/:gender', require('./new-arrivals')); | ||
router.get('/regear/new-arrivals', require('./regear-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,16 @@ | ||
<div> | ||
Available Sizes: | ||
{{each data.availableSizes}} | ||
{{$value}} | ||
{{/each}} | ||
<br> | ||
Color: {{data.color}} | ||
<br> | ||
Original Price: {{data.originalPrice}} | ||
<br> | ||
Regear Price: {{data.regearPrice}} | ||
<br> | ||
|
||
<img src={{data.imgUrl}}> | ||
<br><br> | ||
</div> |