mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
feat: 增加少数派作者新文章推送 (#2122)
This commit is contained in:
@@ -117,7 +117,7 @@ pageClass: routes
|
||||
<Route author="SunShinenny" path="/dilidili/fanju/:id" example="/dilidili/fanju/onepunchman2" :paramsDesc="['番剧id']">
|
||||
|
||||
请打开对应番剧的纵览页(非具体某集),从 url 中最后一位查看番剧 id.(一般为英文)
|
||||
除去超长的番剧(例如海贼)这种具有特殊页面的,绝大多数页面都可以解析.
|
||||
除去'海贼'此类具有特殊页面的超长番剧,绝大多数页面都可以解析.
|
||||
最适合用来追新番
|
||||
|
||||
</Route>
|
||||
|
||||
@@ -664,6 +664,10 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
|
||||
<Route author="LogicJake" example="/sspai/column/104" path="/sspai/column/:id" :paramsDesc="['专栏 id']"/>
|
||||
|
||||
### 作者
|
||||
|
||||
<Route author="SunShinenny" example="/sspai/author/796518" path="/sspai/author/:id" :paramsDesc="['作者 id,可在作者主页URL中找到']"/>
|
||||
|
||||
## 世界卫生组织
|
||||
|
||||
### 媒体中心
|
||||
|
||||
@@ -771,6 +771,7 @@ router.get('/sspai/series', require('./routes/sspai/series'));
|
||||
router.get('/sspai/shortcuts', require('./routes/sspai/shortcutsGallery'));
|
||||
router.get('/sspai/matrix', require('./routes/sspai/matrix'));
|
||||
router.get('/sspai/column/:id', require('./routes/sspai/column'));
|
||||
router.get('/sspai/author/:id', require('./routes/sspai/author'));
|
||||
|
||||
// 异次元软件世界
|
||||
router.get('/iplay/home', require('./routes/iplay/home'));
|
||||
|
||||
51
lib/routes/sspai/author.js
Normal file
51
lib/routes/sspai/author.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=20&author_ids=${id}&include_total=false`;
|
||||
const resp = await axios({
|
||||
method: 'get',
|
||||
url: api_url,
|
||||
});
|
||||
const data = resp.data.list;
|
||||
let author_nickname = '';
|
||||
let author_id = 0;
|
||||
const items = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const link = `https://sspai.com/post/${item.id}`;
|
||||
let description = '';
|
||||
|
||||
const key = `sspai: ${item.id}`;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
if (value) {
|
||||
description = value;
|
||||
} else {
|
||||
const response = await axios({ method: 'get', url: link });
|
||||
const $ = cheerio.load(response.data);
|
||||
description = $('div.content.wangEditor-txt.clock').html();
|
||||
ctx.cache.set(key, description);
|
||||
}
|
||||
|
||||
// 将作者名称和id赋值给nickname和id
|
||||
author_nickname = item.author.nickname;
|
||||
author_id = item.author.id;
|
||||
|
||||
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: `${author_nickname} - 少数派作者`,
|
||||
link: `https://sspai.com/user/${author_id}/posts`,
|
||||
description: `${author_nickname} 更新推送 `,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -21,7 +21,7 @@ module.exports = async (ctx) => {
|
||||
} else {
|
||||
const response = await axios({ method: 'get', url: link });
|
||||
const $ = cheerio.load(response.data);
|
||||
description = $('#article-content > div').html();
|
||||
description = $('div.content.wangEditor-txt.clock').html();
|
||||
ctx.cache.set(key, description);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user