feat(route): add 零博客 (#10035)

This commit is contained in:
Ethan Shen
2022-06-27 20:42:08 +08:00
committed by GitHub
parent a96af536fc
commit d6e730de4c
5 changed files with 85 additions and 0 deletions

View File

@@ -278,6 +278,18 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
<Route author="a180285" example="/blogs/jingwei.link" path="/blogs/jingwei.link"/> <Route author="a180285" example="/blogs/jingwei.link" path="/blogs/jingwei.link"/>
## 零博客
### 分类
<Route author="nczitzk" example="/agora0/initium" path="/agora0/:category?" :paramsDesc="['分类,见下表,默认为 initium即端传媒']">
| muitinⒾ | aidemnⒾ | srettaⓂ | qⓅ | sucoⓋ |
| ------- | ------- | ------- | -- | ----- |
| initium | inmedia | matters | pq | vocus |
</Route>
## 每日安全 ## 每日安全
### 推送 ### 推送

54
lib/v2/agora0/index.js Normal file
View File

@@ -0,0 +1,54 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'initium';
const rootUrl = 'https://agora0.gitlab.io';
const currentUrl = `${rootUrl}/blog/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('.card span:not(.comments) a')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.author = content('meta[name="author"]').attr('content');
item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content'));
item.description = content('.post-content').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};

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

@@ -0,0 +1,13 @@
module.exports = {
'gitlab.io': {
_name: 'GitLab',
agora0: [
{
title: '零博客',
docs: 'https://docs.rsshub.app/blog.html#ling-bo-ke-fen-lei',
source: ['/blog/:category', '/'],
target: '/agora0/:category',
},
],
},
};

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

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./index'));
};