feat(route): add new route "konghq/blog-posts" (#14414)
* Feature: add new route honghq/blog-posts * Update comment of route konghq/blog-posts * Update lib/v2/konghq/blog-posts.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/konghq/blog-posts.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Add radar.js for konghq route. ---------
This commit is contained in:
parent
dc4eb8d02b
commit
7a76fc009c
|
|
@ -0,0 +1,52 @@
|
|||
// Get the lastest blog posts of https://konghq.com/
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const BASE_URL = 'https://konghq.com';
|
||||
const BLOG_POSTS_URL = `${BASE_URL}/blog`;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
// Always get the posts on the first page.
|
||||
const url = `${BLOG_POSTS_URL}/page/1`;
|
||||
|
||||
// Request and parse the index page to get the posts
|
||||
const { data: response } = await got(url);
|
||||
const $ = cheerio.load(response);
|
||||
const nextData = JSON.parse($('#__NEXT_DATA__').text());
|
||||
const posts = nextData.props.pageProps.cardsPaged.cards.map((item) => {
|
||||
const title = item.title;
|
||||
const author = item.authors.map((author) => author.title).join(', ');
|
||||
const category = item.term.title;
|
||||
|
||||
const link = `${BASE_URL}${item.link.href}`;
|
||||
const pubDate = parseDate(item.publishedAt);
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
pubDate,
|
||||
author,
|
||||
category,
|
||||
};
|
||||
});
|
||||
|
||||
// Request each post to get the details content as "description"
|
||||
const items = await Promise.all(
|
||||
posts.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
// Update the description to post's main content
|
||||
item.description = $('section[class^="blog_sections"]').first().html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Kong Inc(konghq.com) blog posts`,
|
||||
link: BLOG_POSTS_URL,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/blog-posts': ['piglei'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'konghq.com': {
|
||||
_name: 'Kong API 网关平台',
|
||||
'.': [
|
||||
{
|
||||
title: '博客最新文章',
|
||||
docs: 'https://docs.rsshub.app/routes/programming#kong-api-wang-guan-ping-tai-bo-ke-zui-xin-wen-zhang',
|
||||
source: ['/blog/*'],
|
||||
target: '/konghq/blog-posts',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/blog-posts', require('./blog-posts'));
|
||||
};
|
||||
|
|
@ -502,6 +502,14 @@ Subscribe to the updates (threads and submission) from a paritcular Hacker News
|
|||
|
||||
<Route author="running-grass" radar="1" example="/issuehunt/funded/DIYgod/RSSHub" path="/issuehunt/funded/:username/:repo" paramsDesc={['Github user/org','Repository name']} />
|
||||
|
||||
## Kong API 网关平台 {#kong-api-wang-guan-ping-tai}
|
||||
|
||||
[Kong](https://konghq.com/) 是一家开源的 API 网关服务商,此处收集其官网的最新博客文章。
|
||||
|
||||
### 博客最新文章 {#kong-api-wang-guan-ping-tai-bo-ke-zui-xin-wen-zhang}
|
||||
|
||||
<Route author="piglei" example="/konghq/blog-posts" path="/konghq/blog-posts" />
|
||||
|
||||
## LeetCode {#leetcode}
|
||||
|
||||
### Articles {#leetcode-articles}
|
||||
|
|
|
|||
Loading…
Reference in New Issue