Skip to content

Commit

Permalink
feat(route): snow-peak new arrivals (DIYgod#12045)
Browse files Browse the repository at this point in the history
* feat(route): snow-peak new arrivals

* feat: change path to snowpeak/us/new-arrivals

* feat: add pubData and category

* feat: add variants and multiple images

* fix: pubDate
  • Loading branch information
EthanWng97 authored Mar 7, 2023
1 parent 62da7bf commit e287440
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ Language

<RouteEn author="nczitzk" example="/shopback/shopee-mart" path="/shopback/:store" :paramsDesc="['Store, can be found in URL']"/>

## Snow Peak

### New Arrivals(USA)

<RouteEn author="NavePnow" example="/snowpeak/us/new-arrivals" path="/snowpeak/us/new-arrivals"/>

## The Independent

### PS5 stock UK
Expand Down
6 changes: 6 additions & 0 deletions docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa

<Route author="nczitzk" example="/shopback/shopee-mart" path="/shopback/:store" :paramsDesc="['店铺名,可在 URL 中找到']"/>

## Snow Peak

### New Arrivals(USA)

<Route author="NavePnow" example="/snowpeak/us/new-arrivals" path="/snowpeak/us/new-arrivals"/>

## The Independent

### PS5 stock UK
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/snowpeak/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/us/new-arrivals': ['NavePnow'],
};
13 changes: 13 additions & 0 deletions lib/v2/snowpeak/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'snowpeak.com': {
_name: 'Snow Peak',
'.': [
{
title: 'New Arrivals(USA)',
docs: 'https://docs.rsshub.app/shopping.html#snow-peak',
source: ['/collections/new-arrivals', '/'],
target: '/snowpeak/us/new-arrivals',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/snowpeak/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/us/new-arrivals', require('./us-new-arrivals'));
};
11 changes: 11 additions & 0 deletions lib/v2/snowpeak/templates/new-arrivals.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
Variant:
<br>
{{each product.variants}}
{{$value.name}}
<br>
{{/each}}
{{each product.images}}
<img src={{$value}}>
{{/each}}
</div>
45 changes: 45 additions & 0 deletions lib/v2/snowpeak/us-new-arrivals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const cheerio = require('cheerio');
const host = 'https://www.snowpeak.com';
module.exports = async (ctx) => {
const url = `${host}/collections/new-arrivals`;
const response = await got({
method: 'get',
url,
});
const data = response.data;

const $ = cheerio.load(data);
const list = $('.element.product-tile')
.map(function () {
const data = {};
const product = $(this).find('.product-data').data('product');
data.title = product.title;
data.link = `${host}/products/${product.handle}`;
data.pubDate = new Date(product.published_at).toUTCString();
data.category = product.tags;
data.variants = product.variants.map((item) => item.name);
data.description =
product.description +
art(path.join(__dirname, 'templates/new-arrivals.art'), {
product,
});

return data;
})
.get();
ctx.state.data = {
title: 'Snow Peak - New Arrivals',
link: `${host}/new-arrivals`,
description: 'Snow Peak - New Arrivals',
item: list.map((item) => ({
title: item.title,
category: item.category,
description: item.description,
pubDate: item.pubDate,
link: item.link,
})),
};
};

0 comments on commit e287440

Please sign in to comment.