feat: add aliyun kernel blog (#3572)

This commit is contained in:
Attenuation 2019-12-12 17:58:14 +08:00 committed by DIYgod
parent 49a0dadb34
commit 5c70eb95f8
3 changed files with 69 additions and 0 deletions

View File

@ -32,6 +32,12 @@ pageClass: routes
<Route author="xyqfer" example="/leemeng" path="/leemeng"/>
## 阿里云系统组技术博客
### 首页
<Route author="attenuation" example="/aliyun-kernel/index" path="/aliyun-kernel/index"/>
## 财新博客
### 用户博客

View File

@ -2034,4 +2034,7 @@ router.get('/ikea/uk/offer', require('./routes/ikea/uk/offer'));
// Mastodon
router.get('/mastodon/timeline/:site/:only_media?', require('./routes/mastodon/timeline'));
// Kernel Aliyun
router.get('/aliyun-kernel/index', require('./routes/aliyun-kernel/index'));
module.exports = router;

View File

@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const baseUrl = 'https://kernel.taobao.org/';
const response = await got({
method: 'get',
url: baseUrl,
headers: {
Referer: baseUrl,
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.container .post-item').get();
const ProcessFeed = (data) => {
const $ = cheerio.load(data);
// 提取内容
return $('.container .post-content').html();
};
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const $a = $('.article-title > a');
const link = baseUrl + $a.attr('href');
// const publish_time = $('.date-label').text();
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: link,
});
const description = ProcessFeed(response.data);
const single = {
title: $a.text(),
description,
link: link,
// pubDate: publish_time,
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: 'Kernel Aliyun',
link: baseUrl,
item: items,
};
};