mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): duplicate entries in the Blizzard feed (#12828)
* fix(route): duplicate entries in the Blizzard feed * refactor: migrate to v2 ---------
This commit is contained in:
+1
-1
@@ -3408,7 +3408,7 @@ router.get('/rescuetime/release-notes/:os?', lazyloadRouteHandler('./routes/resc
|
||||
router.get('/totalcommander/whatsnew', lazyloadRouteHandler('./routes/totalcommander/whatsnew'));
|
||||
|
||||
// Blizzard
|
||||
router.get('/blizzard/news/:language?/:category?', lazyloadRouteHandler('./routes/blizzard/news'));
|
||||
// router.get('/blizzard/news/:language?/:category?', lazyloadRouteHandler('./routes/blizzard/news'));
|
||||
|
||||
// DeepMind
|
||||
// router.get('/deepmind/blog/:category?', lazyloadRouteHandler('./routes/deepmind/blog'));
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/news/:language?/:category?': ['nczitzk'],
|
||||
};
|
||||
@@ -5,37 +5,36 @@ module.exports = async (ctx) => {
|
||||
const category = ctx.params.category || '';
|
||||
const language = ctx.params.language || 'en-us';
|
||||
|
||||
const rootUrl = `https://${language === 'zh-cn' ? 'cn.' : ''}news.blizzard.com`;
|
||||
const rootUrl = 'https://news.blizzard.com';
|
||||
const currentUrl = `${rootUrl}/${language}/${category}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
const apiUrl = `${rootUrl}/${language}/blog/list`;
|
||||
const response = await got(apiUrl, {
|
||||
searchParams: {
|
||||
community: category === '' ? 'all' : category,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response.data.html, null, false);
|
||||
|
||||
const list = $('.FeaturedArticle-text a, .ArticleListItem article a')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
const list = $('.FeaturedArticle-text > a, .ArticleListItem > article > a')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const detailResponse = await got(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.author = content('.ArticleDetail-bylineAuthor').text();
|
||||
item.description = content('.ArticleDetail-content').html();
|
||||
item.description = content('.ArticleDetail-headingImageBlock').html() + content('.ArticleDetail-content').html();
|
||||
item.pubDate = content('.ArticleDetail-subHeadingLeft time').attr('timestamp');
|
||||
|
||||
return item;
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'blizzard.com': {
|
||||
_name: 'Blizzard',
|
||||
news: [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/game.html#blizzard',
|
||||
source: ['/:language/:category?', '/:language'],
|
||||
target: '/blizzard/news/:language/:category?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/news/:language?/:category?', require('./news'));
|
||||
};
|
||||
Reference in New Issue
Block a user