forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DIYgod#289 Hexo Next theme RSS support (DIYgod#395)
* DIYgod#289 Hexo Next theme RSS support * docs * better title & description * parese 5 article by default
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 | |
- Release note | ||
- 推酷 | ||
- 周刊 | ||
- Hexo | ||
- Next 主题 | ||
- 小米 | ||
- 众筹 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |