feat(route): add 鸟哥笔记首页 (#7085)
* feat: add 鸟哥笔记首页 * style: revert useless changes
This commit is contained in:
parent
eaf9b4c6a6
commit
871c56f172
|
|
@ -1588,6 +1588,10 @@ column 为 third 时可选的 category:
|
|||
|
||||
## 鸟哥笔记
|
||||
|
||||
### 首页
|
||||
|
||||
<Route author="WenryXu" example="/ngbj" path="/ngbj"/>
|
||||
|
||||
### 今日事
|
||||
|
||||
<Route author="KotoriK" example="/ngbj/today" path="/ngbj/today"/>
|
||||
|
|
|
|||
|
|
@ -3162,6 +3162,7 @@ router.get('/gov/chongqing/ljxq/zwgk/:caty', require('./routes/gov/chongqing/ljx
|
|||
router.get('/12379', require('./routes/12379/index'));
|
||||
|
||||
// 鸟哥笔记
|
||||
router.get('/ngbj', require('./routes/niaogebiji/index'));
|
||||
router.get('/ngbj/today', require('./routes/niaogebiji/today'));
|
||||
router.get('/ngbj/cat/:cat', require('./routes/niaogebiji/cat'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.niaogebiji.com/`,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const postList = $('.articleListBox').find('.articleBox').get();
|
||||
const result = await Promise.all(
|
||||
postList.map(async (item) => {
|
||||
const title = $(item).find('.article').find('a').find('.articleTitle').text();
|
||||
const link = 'https://www.niaogebiji.com' + $(item).find('.article').find('a').attr('href');
|
||||
const guid = link;
|
||||
const pubDate = new Date(parseInt($(item).attr('data-timepoint')) * 1000).toUTCString();
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: link,
|
||||
guid: guid,
|
||||
pubDate: pubDate,
|
||||
description: '',
|
||||
};
|
||||
|
||||
const description_key = 'niaogebiji' + guid;
|
||||
const description_value = await ctx.cache.get(description_key);
|
||||
|
||||
if (description_value) {
|
||||
single.description = description_value;
|
||||
} else {
|
||||
const temp = await got(link);
|
||||
single.description = $(temp.data).find('.article').find('.pc_content').html();
|
||||
ctx.cache.set(description_key, single.description);
|
||||
}
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = { title: '鸟哥笔记', link: 'https://www.niaogebiji.com/', item: result };
|
||||
};
|
||||
Loading…
Reference in New Issue