mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: 添加对【少数派 sspai 按标签更新文章】的支持 (#3220)
This commit is contained in:
@@ -603,6 +603,10 @@ pageClass: routes
|
||||
|
||||
<Route author="SunShinenny" example="/sspai/topic/250" path="/sspai/topic/:id" :paramsDesc="['专题 id,可在专题主页URL中找到']"/>
|
||||
|
||||
### 标签订阅
|
||||
|
||||
<Route author="Jeason0228" example="/sspai/tag/apple" path="/sspai/tag/:keyword" :paramsDesc="['关键词']"/>
|
||||
|
||||
## 世界卫生组织
|
||||
|
||||
### 媒体中心
|
||||
|
||||
@@ -716,6 +716,7 @@ router.get('/sspai/column/:id', require('./routes/sspai/column'));
|
||||
router.get('/sspai/author/:id', require('./routes/sspai/author'));
|
||||
router.get('/sspai/topics', require('./routes/sspai/topics'));
|
||||
router.get('/sspai/topic/:id', require('./routes/sspai/topic'));
|
||||
router.get('/sspai/tag/:keyword', require('./routes/sspai/tag'));
|
||||
|
||||
// 异次元软件世界
|
||||
router.get('/iplay/home', require('./routes/iplay/home'));
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const keyword = ctx.params.keyword;
|
||||
const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=50&has_tag=1&tag=${keyword}&include_total=false`;
|
||||
const host = `https://beta.sspai.com/tag/${keyword}`;
|
||||
const resp = await got({
|
||||
method: 'get',
|
||||
url: api_url,
|
||||
headers: {
|
||||
Referer: host,
|
||||
},
|
||||
});
|
||||
const data = resp.data.list;
|
||||
const items = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const link = `https://sspai.com/post/${item.id}`;
|
||||
let description = ``;
|
||||
const key = item.id;
|
||||
const value = await ctx.cache.get(key);
|
||||
if (value) {
|
||||
description = value;
|
||||
} else {
|
||||
const response = await got({ method: 'get', url: link, headers: { Referer: host } });
|
||||
const $ = cheerio.load(response.data);
|
||||
description = $('div.content.wangEditor-txt.clock').html();
|
||||
ctx.cache.set(key, description);
|
||||
}
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
description: description,
|
||||
link: link,
|
||||
pubDate: new Date(item.released_at * 1000).toUTCString(),
|
||||
author: item.author.nickname,
|
||||
};
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `#${keyword} - 少数派`,
|
||||
link: host,
|
||||
description: `${keyword} 更新推送 `,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user