diff --git a/docs/programming.md b/docs/programming.md index 5807575d96..85f034103b 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -638,11 +638,15 @@ GitHub 官方也提供了一些 RSS: ### 频道 - + ### 用户 - + + +### 博客 + + ## TesterHome diff --git a/lib/v2/segmentfault/blogs.js b/lib/v2/segmentfault/blogs.js new file mode 100644 index 0000000000..436d040c57 --- /dev/null +++ b/lib/v2/segmentfault/blogs.js @@ -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, + }; +}; diff --git a/lib/v2/segmentfault/maintainer.js b/lib/v2/segmentfault/maintainer.js index 264c59f75f..d8dfd4ec09 100644 --- a/lib/v2/segmentfault/maintainer.js +++ b/lib/v2/segmentfault/maintainer.js @@ -1,4 +1,5 @@ module.exports = { + '/blogs/:tag': ['shiluanzzz'], '/channel/:name': ['LogicJake', 'Fatpandac'], - '/user/:name': ['leyuuu', 'Fatpandac'], + '/user/:name': ['leyuuu', 'Fatpandac'] }; diff --git a/lib/v2/segmentfault/radar.js b/lib/v2/segmentfault/radar.js index 5c95675b45..d73bc834ac 100644 --- a/lib/v2/segmentfault/radar.js +++ b/lib/v2/segmentfault/radar.js @@ -6,14 +6,20 @@ module.exports = { title: '频道', docs: 'https://docs.rsshub.app/programming.html#segmentfault', source: ['/channel/:name'], - target: '/channel/:name', + target: '/segmentfault/channel/:name', }, { title: '用户', docs: 'https://docs.rsshub.app/programming.html#segmentfault', 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", + } ], }, }; diff --git a/lib/v2/segmentfault/router.js b/lib/v2/segmentfault/router.js index 3990afd991..7a701a952e 100644 --- a/lib/v2/segmentfault/router.js +++ b/lib/v2/segmentfault/router.js @@ -1,4 +1,5 @@ module.exports = function (router) { + router.get("/blogs/:tag", require("./blogs")); router.get('/channel/:name', require('./channel')); router.get('/user/:name', require('./user')); };