Skip to content

Commit

Permalink
feat: add jian-ning blog (DIYgod#5600)
Browse files Browse the repository at this point in the history
Co-authored-by: Chang Lan <[email protected]>
  • Loading branch information
2 people authored and luyuhuang committed Sep 9, 2020
1 parent 710df5b commit 106bdbd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
16 changes: 15 additions & 1 deletion assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@
},
],
},
'wenxuecity.com/': {
'wenxuecity.com': {
_name: '文学城',
blog: [
{
Expand All @@ -2276,6 +2276,9 @@
docs: 'https://docs.rsshub.app/bbs.html#wen-xue-cheng-bo-ke',
source: '/myoverview/:id',
target: 'wenxuecity/blog/:id',
},
],
},
'buaq.net': {
_name: '不安全资讯',
'.': [
Expand All @@ -2287,4 +2290,15 @@
},
],
},
'jian-ning.com': {
_name: '建宁闲谈',
'.': [
{
title: '文章',
docs: 'https://docs.rsshub.app/blog.html#jian-ning-xian-tan',
source: '/*',
target: '/blogs/jianning',
},
],
},
});
6 changes: 6 additions & 0 deletions docs/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pageClass: routes

<Route author="kt286" example="/daxiaamu/home" path="/daxiaamu/home"/>

## 建宁闲谈

### 文章

<Route author="changlan" example="/blogs/jianning" path="/blogs/jianning" radar="1"/>

## 敬维博客

### 文章
Expand Down
6 changes: 0 additions & 6 deletions docs/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5

<Route author="nczitzk" example="/kongfz/people/5032170" path="/kongfz/people/:id" :paramsDesc="['用户 id, 可在对应用户页 URL 中找到']"/>

## 孔夫子旧书网

### 用户动态

<Route author="nczitzk" example="/kongfz/people/5032170" path="/kongfz/people/:id" :paramsDesc="['用户 id, 可在对应用户页 URL 中找到']"/>

### 店铺上架

<Route author="nczitzk" example="/kongfz/shop/238901/1" path="/kongfz/shop/:id/:cat?" :paramsDesc="['店铺 id, 可在对应店铺页 URL 中找到', '分类 id,可在对应分类页 URL 中找到,默认为店铺最新上架']"/>
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3185,4 +3185,7 @@ router.get('/secshi', require('./routes/secshi/index'));
// 出海笔记
router.get('/chuhaibiji', require('./routes/chuhaibiji/index'));

// 建宁闲谈
router.get('/blogs/jianning', require('./routes/blogs/jianning'));

module.exports = router;
45 changes: 45 additions & 0 deletions lib/routes/blogs/jianning.js
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),
};
};

0 comments on commit 106bdbd

Please sign in to comment.