mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
feat: add oschina topic (#2570)
* feat: add oschina topic * remove ua * format
This commit is contained in:
@@ -367,6 +367,7 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
| xxiaobian |
|
| xxiaobian |
|
||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
### 数字型账号用户博客
|
### 数字型账号用户博客
|
||||||
|
|
||||||
<Route author="dxmpalb" example="/oschina/u/3920392" path="/oschina/u/:id" :paramsDesc="['用户 id, 可通过查看用户博客网址得到,以 u/数字结尾,数字即为 id']">
|
<Route author="dxmpalb" example="/oschina/u/3920392" path="/oschina/u/:id" :paramsDesc="['用户 id, 可通过查看用户博客网址得到,以 u/数字结尾,数字即为 id']">
|
||||||
@@ -377,6 +378,10 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
### 问答主题
|
||||||
|
|
||||||
|
<Route author="loveely7" example="/oschina/topic/weekly-news" path="/oschina/topic/:topic" :paramsDesc="['主题名, 可从[全部主题](https://www.oschina.net/question/topics)进入主题页, 在 URL 中找到']"/>
|
||||||
|
|
||||||
## 看雪
|
## 看雪
|
||||||
|
|
||||||
### 论坛
|
### 论坛
|
||||||
|
|||||||
@@ -420,6 +420,7 @@ router.get('/linkedkeeper/:type/:id?', require('./routes/linkedkeeper/index'));
|
|||||||
router.get('/oschina/news/:category?', require('./routes/oschina/news'));
|
router.get('/oschina/news/:category?', require('./routes/oschina/news'));
|
||||||
router.get('/oschina/user/:id', require('./routes/oschina/user'));
|
router.get('/oschina/user/:id', require('./routes/oschina/user'));
|
||||||
router.get('/oschina/u/:id', require('./routes/oschina/u'));
|
router.get('/oschina/u/:id', require('./routes/oschina/u'));
|
||||||
|
router.get('/oschina/topic/:topic', require('./routes/oschina/topic'));
|
||||||
|
|
||||||
// 安全客
|
// 安全客
|
||||||
router.get('/aqk/vul', require('./routes/aqk/vul'));
|
router.get('/aqk/vul', require('./routes/aqk/vul'));
|
||||||
|
|||||||
54
lib/routes/oschina/topic.js
Normal file
54
lib/routes/oschina/topic.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
const url = require('url');
|
||||||
|
const got = require('@/utils/got');
|
||||||
|
const date = require('@/utils/date');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
async function load(link) {
|
||||||
|
const res = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: link,
|
||||||
|
});
|
||||||
|
const content = cheerio.load(res.data);
|
||||||
|
content('.ad-wrap').remove();
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const topic = ctx.params.topic;
|
||||||
|
const topicUrl = `https://www.oschina.net/question/topic/${topic}?show=time`;
|
||||||
|
|
||||||
|
const $ = await load(topicUrl);
|
||||||
|
const topicName = $('.topic-info > .topic-header > h3').text();
|
||||||
|
const list = $('#questionList').find('.question-item');
|
||||||
|
const count = [];
|
||||||
|
for (let i = 0; i < Math.min(list.length, 10); i++) {
|
||||||
|
count.push(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
const resultItem = await Promise.all(
|
||||||
|
count.map(async (i) => {
|
||||||
|
const each = $(list[i]);
|
||||||
|
const originalUrl = each.find('.header').attr('href');
|
||||||
|
|
||||||
|
const item = {
|
||||||
|
title: each.find('.header').text(),
|
||||||
|
link: url.resolve('https://www.oschina.net', encodeURI(originalUrl)),
|
||||||
|
author: date(each.find('.extra > .list > .item:nth-of-type(1)').text()),
|
||||||
|
pubDate: date(each.find('.extra > .list > .item:nth-of-type(2)').text()),
|
||||||
|
};
|
||||||
|
|
||||||
|
item.description = await ctx.cache.tryGet(originalUrl, async () => {
|
||||||
|
const content = await load(item.link);
|
||||||
|
return content('#articleContent').html();
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.resolve(item);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `开源中国-${topicName}`,
|
||||||
|
link: topicUrl,
|
||||||
|
item: resultItem,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user