mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +08:00
feat: add SteamGifts - Discussions (#2179)
This commit is contained in:
@@ -97,6 +97,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
||||
|
||||
<Route author="maple3142" example="/steam/news/282800" path="/steam/news/:appids" :paramsDesc="['游戏 id']"/>
|
||||
|
||||
## SteamGifts
|
||||
|
||||
### Discussions
|
||||
|
||||
<Route author="whtsky" example="/steamgifts/discussions" path="/steamgifts/discussions/:category?" :paramsDesc="['分类名称,默认为All']"/>
|
||||
|
||||
## 旅法师营地
|
||||
|
||||
### 旅法师营地
|
||||
|
||||
@@ -1316,4 +1316,7 @@ router.get('/maxnews/dota2', require('./routes/maxnews/dota2'));
|
||||
// 数英网最新文章
|
||||
router.get('/digitaling/index', require('./routes/digitaling/index'));
|
||||
|
||||
// Steamgifts
|
||||
router.get('/steamgifts/discussions/:category?', require('./routes/steamgifts/discussions'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
58
lib/routes/steamgifts/discussions.js
Normal file
58
lib/routes/steamgifts/discussions.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const axios = require('@/utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'https://www.steamgifts.com';
|
||||
const discussionsIndexUrl = url.resolve(host, '/discussions');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
|
||||
const categoryUrl = category ? discussionsIndexUrl + `/${category}` : discussionsIndexUrl;
|
||||
const response = await axios.get(categoryUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const links = $('a.table__column__heading')
|
||||
.slice(0, 20)
|
||||
.map((i, e) => url.resolve(host, $(e).attr('href')))
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
links.map(async (link) => {
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return JSON.parse(cache);
|
||||
}
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Referer: categoryUrl,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const timestamp = Number($('.comment__actions span').data('timestamp'));
|
||||
const date = new Date(timestamp * 1000);
|
||||
|
||||
const item = {
|
||||
title: $('title').text(),
|
||||
description: $('.comment__description').html(),
|
||||
pubDate: date.toUTCString(),
|
||||
link,
|
||||
guid: link,
|
||||
};
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(item));
|
||||
|
||||
return item;
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Steamgifts - Discussions - ${category || 'All'}`,
|
||||
link: categoryUrl,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user