* #289 Hexo Next theme RSS support * docs * better title & description * parese 5 article by default
This commit is contained in:
parent
ddc7ff11b5
commit
a0475c1746
|
|
@ -187,6 +187,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
|||
- Release note
|
||||
- 推酷
|
||||
- 周刊
|
||||
- Hexo
|
||||
- Next 主题
|
||||
- 小米
|
||||
- 众筹
|
||||
|
||||
|
|
|
|||
|
|
@ -1548,6 +1548,16 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
|||
| -------- | -------- | -------- | -------- |
|
||||
| prog | design | startup | tech |
|
||||
|
||||
## Hexo
|
||||
|
||||
### Next 主题
|
||||
|
||||
举例:[http://rsshub.app/hexo/next/fengkx.top](http://rsshub.app/hexo/next/fengkx.top)
|
||||
|
||||
路由: `/hexo/next/:url`
|
||||
|
||||
参数: url 博客 Url 不带协议头
|
||||
|
||||
## 小米
|
||||
|
||||
### 众筹
|
||||
|
|
|
|||
|
|
@ -354,6 +354,9 @@ router.get('/firefox/release/:platform', require('./routes/firefox/release'));
|
|||
// tuicool
|
||||
router.get('/tuicool/mags/:type', require('./routes/tuicool/mags'));
|
||||
|
||||
// Hexo
|
||||
router.get('/hexo/next/:url', require('./routes/hexo/next'));
|
||||
|
||||
// 小米
|
||||
router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `http://${ctx.params.url}`;
|
||||
const res = await axios_ins.get(`${url}/archives`);
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const list = $('.post-header');
|
||||
|
||||
const count = [];
|
||||
for (let i = 0; i < Math.min(list.length, 5); i++) {
|
||||
count.push(i);
|
||||
}
|
||||
const out = await Promise.all(
|
||||
count.map(async (i) => {
|
||||
const each = $(list[i]);
|
||||
const storyLink = each.find('.post-title-link').attr('href');
|
||||
const item = {
|
||||
title: each.find('[itemprop=name]').text(),
|
||||
link: encodeURI(`${url}${storyLink}`),
|
||||
};
|
||||
const key = item.link;
|
||||
const value = ctx.cache.get(key);
|
||||
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
const storyDeatil = await axios_ins.get(item.link);
|
||||
const data = storyDeatil.data;
|
||||
const $ = cheerio.load(data);
|
||||
item.pubDate = $('time').attr('datetime');
|
||||
item.description = $('.post-body').html();
|
||||
ctx.cache.set(key, item.descriptio, 6 * 60 * 60);
|
||||
}
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: $('.site-title').text(),
|
||||
link: url,
|
||||
description: $('[name=description]').attr('content'),
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue