feat(route): add eprice (#8247)
Co-authored-by: SettingDust <settingdust@gmail.com>
This commit is contained in:
parent
33de44df34
commit
d8aa7357e5
|
|
@ -224,6 +224,18 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## ePrice
|
||||
|
||||
<Route author="TonyRL" example="/eprice/tw" path="/eprice/:region?" :paramsDesc="['地区,预设为 tw']">
|
||||
|
||||
地区:
|
||||
|
||||
| hk | tw |
|
||||
| ---- | ---- |
|
||||
| 香港 | 台湾 |
|
||||
|
||||
</Route>
|
||||
|
||||
## Esquirehk
|
||||
|
||||
### Tag
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:region?': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
module.exports = {
|
||||
'eprice.com.tw': {
|
||||
_name: 'ePrice',
|
||||
'.': [
|
||||
{
|
||||
title: 'ePrice 比價王',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#eprice',
|
||||
source: ['/'],
|
||||
target: '/:region?',
|
||||
},
|
||||
],
|
||||
},
|
||||
'eprice.com.hk': {
|
||||
_name: 'ePrice',
|
||||
'.': [
|
||||
{
|
||||
title: 'ePrice 香港',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#eprice',
|
||||
source: ['/'],
|
||||
target: '/:region?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:region?', require('./rss'));
|
||||
};
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
const got = require('@/utils/got');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const region = ctx.params.region ?? 'tw';
|
||||
|
||||
const feed = await parser.parseURL(`https://www.eprice.com.${region}/news/rss.xml`);
|
||||
|
||||
feed.items.forEach((e) => {
|
||||
e.link = e.link.replace(/^http:\/\//i, 'https://');
|
||||
});
|
||||
|
||||
const renderDesc = (desc) =>
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
desc,
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
headers: {
|
||||
Referer: `https://www.eprice.com.${region}`,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
// remove unwanted elements
|
||||
$('noscript').remove();
|
||||
$('div.ad-336x280-g').remove();
|
||||
$('div.ad-728x90-g').remove();
|
||||
$('.adsbygoogle').remove();
|
||||
$('.join-eprice-fb').remove();
|
||||
$('div.clear').remove();
|
||||
$('div.text-left').remove();
|
||||
$('div.signature').remove();
|
||||
$('div[id^=dablewidget]').remove();
|
||||
|
||||
// extract categories
|
||||
item.category = item.categories;
|
||||
|
||||
// fix lazyload image
|
||||
$('img').each((_, e) => {
|
||||
e = $(e);
|
||||
if (e.attr('data-original')) {
|
||||
e.attr('src', e.attr('data-original'));
|
||||
e.removeAttr('class');
|
||||
e.removeAttr('data-original');
|
||||
e.removeAttr('data-title');
|
||||
e.removeAttr('data-thumbnail');
|
||||
e.removeAttr('data-url');
|
||||
}
|
||||
});
|
||||
|
||||
// remove unwanted key value
|
||||
delete item.categories;
|
||||
delete item.content;
|
||||
delete item.contentSnippet;
|
||||
delete item.creator;
|
||||
delete item.enclosure;
|
||||
delete item.isoDate;
|
||||
|
||||
item.description = renderDesc($('div.user-comment-block').html() ?? $('div.content').html());
|
||||
item.pubDate = parseDate(item.pubDate);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
image: feed.image.url,
|
||||
language: feed.language,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
image: feed.image.url,
|
||||
language: feed.language,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1 @@
|
|||
{{ desc }}
|
||||
Loading…
Reference in New Issue