feat(route): add Apache APISIX 博客 & 云原生社区博客 & 支流科技博客 (#12294)

* Add apiseven blog

* Add apache apisix blog

* Add cloudnative blog

* Add radar.js and docs

* Fix code styles

* Fix code styles

* Use `markdown-it` to render the description
This commit is contained in:
Desmond Stonie
2023-04-16 03:40:36 +08:00
committed by GitHub
parent 24a15810c4
commit afcd21b3b3
13 changed files with 187 additions and 0 deletions

View File

@@ -16,6 +16,12 @@ pageClass: routes
</Route>
## Apache
### APISIX 博客
<Route author="aneasystone" example="/apache/apisix/blog" path="/apache/apisix/blog"/>
## archdaily
### 首页
@@ -411,6 +417,18 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
<Route author="XinRoom" example="/ddosi/category/黑客工具" path="/ddosi/category/:category?"/>
## 云原生社区
### 博客
<Route author="aneasystone" example="/cloudnative/blog" path="/cloudnative/blog"/>
## 支流科技
### 博客
<Route author="aneasystone" example="/apiseven/blog" path="/apiseven/blog"/>
## 竹白
### 文章

View File

@@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
async function getArticles() {
const url = 'https://apisix.apache.org/zh/blog/';
const { data: res } = await got(url);
const $ = cheerio.load(res);
const articles = $('section.sec_gjjg').eq(1).find('article');
return articles.toArray().map((elem) => {
const a = $(elem).find('header > a');
return {
title: a.find('h2').text(),
description: a.find('p').text(),
link: a.attr('href'),
pubDate: parseDate($(elem).find('footer').find('time').attr('datetime')),
category: $(elem)
.find('header div a')
.toArray()
.map((elem) => $(elem).text()),
};
});
}
module.exports = async (ctx) => {
const articles = await getArticles();
ctx.state.data = {
title: 'Blog | Apache APISIX',
link: 'https://apisix.apache.org/zh/blog/',
item: articles,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/apisix/blog': ['aneasystone'],
};

13
lib/v2/apache/radar.js Normal file
View File

@@ -0,0 +1,13 @@
module.exports = {
'apache.org': {
_name: 'Apache',
apisix: [
{
title: 'APISIX 博客',
docs: 'https://docs.rsshub.app/blog.html#apache',
source: ['/zh/blog'],
target: () => '/apache/apisix/blog',
},
],
},
};

3
lib/v2/apache/router.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/apisix/blog', require('./apisix/blog'));
};

46
lib/v2/apiseven/blog.js Normal file
View File

@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const md = require('markdown-it')({
html: true,
});
async function getArticles() {
const url = 'https://www.apiseven.com/blog';
const { data: res } = await got(url);
const $ = cheerio.load(res);
const json = JSON.parse($('#__NEXT_DATA__').text());
return json.props.pageProps.list.map((item) => ({
title: item.title,
link: 'https://www.apiseven.com' + item.slug,
pubDate: timezone(parseDate(item.published_at), +8),
category: item.tags,
}));
}
module.exports = async (ctx) => {
const articles = await getArticles();
const items = await Promise.all(
articles.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: res } = await got(item.link);
const $ = cheerio.load(res);
const json = JSON.parse($('#__NEXT_DATA__').text());
return {
title: item.title,
description: md.render(json.props.pageProps.post.content),
link: item.link,
pubDate: item.pubDate,
author: json.props.pageProps.post.author_name,
};
})
)
);
ctx.state.data = {
title: '博客 | 支流科技',
link: 'https://www.apiseven.com/blog',
item: items,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/blog': ['aneasystone'],
};

13
lib/v2/apiseven/radar.js Normal file
View File

@@ -0,0 +1,13 @@
module.exports = {
'apiseven.com': {
_name: '支流科技',
'.': [
{
title: '博客',
docs: 'https://docs.rsshub.app/blog.html#zhi-liu-ke-ji',
source: ['/blog'],
target: () => '/apiseven/blog',
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/blog', require('./blog'));
};

View File

@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
async function getArticles() {
const url = 'https://cloudnative.to/blog/';
const { data: res } = await got(url);
const $ = cheerio.load(res);
const articles = $('div.page-body .stream-item');
return articles.toArray().map((elem) => {
const a = $(elem).find('.article-title > a');
const summary = $(elem).find('.summary-link');
const meta = $(elem).find('.stream-meta .article-metadata');
const time = meta.find('.article-date').text().replace('发布于', '');
return {
title: a.text(),
link: a.attr('href'),
description: summary.text(),
pubDate: timezone(parseDate(time, 'YYYY-MM-DD'), +8),
author: meta.find('span').eq(0).find('a').text(),
category: meta.find('.article-categories a').text(),
};
});
}
module.exports = async (ctx) => {
const articles = await getArticles();
ctx.state.data = {
title: '博客 | 云原生社区(中国)',
link: 'https://cloudnative.to/blog/',
item: articles,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/blog': ['aneasystone'],
};

View File

@@ -0,0 +1,13 @@
module.exports = {
'cloudnative.to': {
_name: '云原生社区',
'.': [
{
title: '博客',
docs: 'https://docs.rsshub.app/blog.html#yun-yuan-sheng-she-qu',
source: ['/blog'],
target: () => '/cloudnative/blog',
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/blog', require('./blog'));
};