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): zagg new arrivals (DIYgod#12059)
* feat(route): zagg new arrivals * Update docs/en/shopping.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * chore: use web api instead * chore: use query instead of params * fix: type * fix: link * Update lib/v2/zagg/new-arrivals.js ---------
- Loading branch information
1 parent
fe96ab5
commit bbac984
Showing
7 changed files
with
94 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 = { | ||
'/new-arrivals/:query?': ['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,52 @@ | ||
const got = require('@/utils/got'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const cheerio = require('cheerio'); | ||
const host = 'https://www.zagg.com/en_us'; | ||
module.exports = async (ctx) => { | ||
const query = ctx.params.query; | ||
const params = new URLSearchParams(query); | ||
const brands = params.get('brand'); | ||
const categories = params.get('cat'); | ||
|
||
const url = `${host}/new-arrivals`; | ||
const response = await got({ | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest', | ||
}, | ||
method: 'post', | ||
url, | ||
searchParams: { | ||
cat: categories, | ||
brand: brands, | ||
}, | ||
}); | ||
const products = response.data.products; | ||
|
||
const $ = cheerio.load(products); | ||
const list = $('.item.product.product-item') | ||
.map(function () { | ||
const data = {}; | ||
const details = $(this).find('.product.details-box').html(); | ||
data.link = $(this).find('.product-item-link').eq(0).attr('href'); | ||
data.title = $(this).find('.product-item-link').text(); | ||
const regex = /(https.*?)\?/; | ||
const imgUrl = $(this).find('img').eq(0).attr('data-src').match(regex)[1]; | ||
const img = art(path.join(__dirname, 'templates/new-arrivals.art'), { | ||
imgUrl, | ||
}); | ||
data.description = details + img; | ||
return data; | ||
}) | ||
.get(); | ||
ctx.state.data = { | ||
title: 'Zagg - New Arrivals', | ||
link: response.url, | ||
description: 'Zagg - New Arrivals', | ||
item: list.map((item) => ({ | ||
title: item.title, | ||
description: item.description, | ||
link: item.link, | ||
})), | ||
}; | ||
}; |
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 @@ | ||
module.exports = { | ||
'zagg.com': { | ||
_name: 'New Arrivals', | ||
'.': [ | ||
{ | ||
title: 'Zagg - New Arrivals', | ||
docs: 'https://docs.rsshub.app/shopping.html#zagg', | ||
source: ['/en_us/new-arrivals'], | ||
target: (_, url) => { | ||
const queryString = url.split('?')[1]; | ||
return `/zagg/new-arrivals/${queryString}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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/:query?', 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,3 @@ | ||
<div> | ||
<img src={{imgUrl}}> | ||
</div> |