mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: add 猿料标签 (#6557)
This commit is contained in:
@@ -413,3 +413,23 @@ pageClass: routes
|
||||
### 金米奖
|
||||
|
||||
<Route author="nczitzk" example="/mi/golden" path="/mi/golden"/>
|
||||
|
||||
## 猿料
|
||||
|
||||
### 标签
|
||||
|
||||
<Route author="nczitzk" example="/yuanliao" path="/yuanliao/:tag/:sort?" :paramsDesc="['标签,见下表,默认为 `utools`', '排序,见下表,默认为最新回复']">
|
||||
|
||||
标签
|
||||
|
||||
| uTools | 插件发布 |
|
||||
| ------ | -------- |
|
||||
| utools | plugins |
|
||||
|
||||
排序
|
||||
|
||||
| 最新回复 | 热门回复 | 新鲜出炉 | 陈年旧贴 |
|
||||
| -------- | ------------- | ---------- | --------- |
|
||||
| | -commentCount | -createdAt | createdAt |
|
||||
|
||||
</Route>
|
||||
|
||||
@@ -3767,6 +3767,9 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet
|
||||
// DailyArt
|
||||
router.get('/dailyart/:language?', require('./routes/dailyart/index'));
|
||||
|
||||
// 猿料
|
||||
router.get('/yuanliao/:tag?/:sort?', require('./routes/yuanliao/index'));
|
||||
|
||||
// 中国政协网
|
||||
router.get('/cppcc/:slug?', require('./routes/gov/cppcc/index'));
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const tag = ctx.params.tag || 'utools';
|
||||
const sort = ctx.params.sort || '';
|
||||
|
||||
const rootUrl = 'https://yuanliao.info';
|
||||
const currentUrl = `${rootUrl}/api/discussions?tags=${tag}&sort=${sort}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const list = response.data.data.map((item) => ({
|
||||
title: item.attributes.title,
|
||||
link: `${rootUrl}/d/${item.id}-${item.attributes.slug}`,
|
||||
pubDate: new Date(item.attributes.lastPostedAt).toUTCString(),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('#flarum-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${tag} - 猿料`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user