mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +08:00
feat(route): segmentfault 新增了每个标签下相关的文章 (#10476)
* new segmentfault blogs * fix radar.js route * fix * docs: linebreak * style: lint
This commit is contained in:
@@ -638,11 +638,15 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
### 频道
|
### 频道
|
||||||
|
|
||||||
<Route author="LogicJake Fatpandac" example="/segmentfault/channel/frontend" path="/segmentfault/channel/:name" :paramsDesc="['频道名称,在频道 URL 可以找到']"/>
|
<Route author="LogicJake Fatpandac" example="/segmentfault/channel/frontend" path="/segmentfault/channel/:name" :paramsDesc="['频道名称,在频道 URL 可以找到']" radar="1"/>
|
||||||
|
|
||||||
### 用户
|
### 用户
|
||||||
|
|
||||||
<Route author="leyuuu Fatpandac" example="/segmentfault/user/minnanitkong" path="/segmentfault/user/:name" :paramsDesc="['用户 Id,用户详情页 URL 可以找到']"/>
|
<Route author="leyuuu Fatpandac" example="/segmentfault/user/minnanitkong" path="/segmentfault/user/:name" :paramsDesc="['用户 Id,用户详情页 URL 可以找到']" radar="1"/>
|
||||||
|
|
||||||
|
### 博客
|
||||||
|
|
||||||
|
<Route author="shiluanzzz" example="/segmentfault/blogs/go" path="/segmentfault/blogs/:tag" :paramsDesc="['标签名称, 在 https://segmentfault.com/tags 中可以找到']" radar="1"/>
|
||||||
|
|
||||||
## TesterHome
|
## TesterHome
|
||||||
|
|
||||||
|
|||||||
38
lib/v2/segmentfault/blogs.js
Normal file
38
lib/v2/segmentfault/blogs.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
|
||||||
|
const host = 'https://segmentfault.com';
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const tag = ctx.params.tag;
|
||||||
|
const apiURL = `https://segmentfault.com/gateway/tag/${tag}/articles?loadMoreType=pagination&initData=true&page=1&sort=newest&pageSize=30`;
|
||||||
|
const response = await got(apiURL);
|
||||||
|
const data = response.data.rows;
|
||||||
|
|
||||||
|
const list = data.map((item) => ({
|
||||||
|
title: item.title,
|
||||||
|
link: new URL(item.url, host).href,
|
||||||
|
author: item.user.name,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
list.map((item) =>
|
||||||
|
ctx.cache.tryGet(item.link, async () => {
|
||||||
|
const response = await got(item.link);
|
||||||
|
const content = cheerio.load(response.data);
|
||||||
|
|
||||||
|
item.description = content('article').html();
|
||||||
|
item.pubDate = parseDate(content('time').attr('datetime'));
|
||||||
|
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `segmentfault-Blogs-${tag}`,
|
||||||
|
link: `${host}/t/${tag}/blogs`,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
'/blogs/:tag': ['shiluanzzz'],
|
||||||
'/channel/:name': ['LogicJake', 'Fatpandac'],
|
'/channel/:name': ['LogicJake', 'Fatpandac'],
|
||||||
'/user/:name': ['leyuuu', 'Fatpandac'],
|
'/user/:name': ['leyuuu', 'Fatpandac']
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,14 +6,20 @@ module.exports = {
|
|||||||
title: '频道',
|
title: '频道',
|
||||||
docs: 'https://docs.rsshub.app/programming.html#segmentfault',
|
docs: 'https://docs.rsshub.app/programming.html#segmentfault',
|
||||||
source: ['/channel/:name'],
|
source: ['/channel/:name'],
|
||||||
target: '/channel/:name',
|
target: '/segmentfault/channel/:name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '用户',
|
title: '用户',
|
||||||
docs: 'https://docs.rsshub.app/programming.html#segmentfault',
|
docs: 'https://docs.rsshub.app/programming.html#segmentfault',
|
||||||
source: ['/u/:name'],
|
source: ['/u/:name'],
|
||||||
target: '/user/:name',
|
target: '/segmentfault/user/:name',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "博客",
|
||||||
|
docs: "https://docs.rsshub.app/programming.html#segmentfault",
|
||||||
|
source: ["/t/:tag/blogs"],
|
||||||
|
target: "/segmentfault/blogs/:tag",
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = function (router) {
|
module.exports = function (router) {
|
||||||
|
router.get("/blogs/:tag", require("./blogs"));
|
||||||
router.get('/channel/:name', require('./channel'));
|
router.get('/channel/:name', require('./channel'));
|
||||||
router.get('/user/:name', require('./user'));
|
router.get('/user/:name', require('./user'));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user