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:
miles
2023-07-18 21:05:34 +08:00
committed by GitHub
parent ab719073be
commit a5ddccc5ae
7 changed files with 84 additions and 63 deletions
+1 -1
View File
@@ -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'));
+3
View File
@@ -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;
+13
View File
@@ -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?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/news/:language?/:category?', require('./news'));
};