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.
feat: add jian-ning blog (DIYgod#5600)
Co-authored-by: Chang Lan <[email protected]>
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 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
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
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,45 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const iconv = require('iconv-lite'); | ||
const url = require('url'); | ||
|
||
module.exports = async (ctx) => { | ||
const base_url = `http://jian-ning.com/all-articles.html`; | ||
const response = await got({ | ||
method: 'get', | ||
url: base_url, | ||
responseType: 'buffer', | ||
}); | ||
const data = iconv.decode(response.data, 'gbk'); | ||
const $ = cheerio.load(data); | ||
const list = $('li'); | ||
const out = list | ||
.map(async (i, item) => { | ||
const link = url.resolve('http://jian-ning.com', $(item).find('a').attr('href')); | ||
const description = await ctx.cache.tryGet(link, async () => { | ||
const result = await got({ | ||
method: 'get', | ||
url: link, | ||
responseType: 'buffer', | ||
headers: { | ||
Referer: base_url, | ||
}, | ||
}); | ||
const content = cheerio.load(iconv.decode(result.data, 'gbk')); | ||
return content('td td').html(); | ||
}); | ||
const post = { | ||
title: $(item).find('a').text(), | ||
link: link, | ||
pubDate: $(item).find('span').text(), | ||
description: description, | ||
}; | ||
return post; | ||
}) | ||
.get(); | ||
ctx.state.data = { | ||
title: $('head > title').text(), | ||
link: base_url, | ||
item: await Promise.all(out), | ||
}; | ||
}; |