feat: add aliyun kernel blog (#3572)
This commit is contained in:
parent
49a0dadb34
commit
5c70eb95f8
|
|
@ -32,6 +32,12 @@ pageClass: routes
|
|||
|
||||
<Route author="xyqfer" example="/leemeng" path="/leemeng"/>
|
||||
|
||||
## 阿里云系统组技术博客
|
||||
|
||||
### 首页
|
||||
|
||||
<Route author="attenuation" example="/aliyun-kernel/index" path="/aliyun-kernel/index"/>
|
||||
|
||||
## 财新博客
|
||||
|
||||
### 用户博客
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue