From 871c56f1725e821bc90209ba5f52d8d9eaa7eed4 Mon Sep 17 00:00:00 2001 From: WenryXu Date: Wed, 17 Mar 2021 05:10:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=B8=9F=E5=93=A5?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E9=A6=96=E9=A1=B5=20(#7085)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 鸟哥笔记首页 * style: revert useless changes --- docs/new-media.md | 4 ++++ lib/router.js | 1 + lib/routes/niaogebiji/index.js | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/routes/niaogebiji/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 3aa64122b..cfbc3c52f 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1588,6 +1588,10 @@ column 为 third 时可选的 category: ## 鸟哥笔记 +### 首页 + + + ### 今日事 diff --git a/lib/router.js b/lib/router.js index acd99937b..d0c58235a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/niaogebiji/index.js b/lib/routes/niaogebiji/index.js new file mode 100644 index 000000000..b21633c42 --- /dev/null +++ b/lib/routes/niaogebiji/index.js @@ -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 }; +};