mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 13:08:14 +08:00
feat(route): segmentfault 新增了每个标签下相关的文章 (#10476)
* new segmentfault blogs * fix radar.js route * fix * docs: linebreak * style: lint
This commit is contained in:
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user