Skip to content

Commit

Permalink
fix(route): niaogebiji (#13354)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Sep 21, 2023
1 parent 6b7949a commit cfe8569
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 210 deletions.
6 changes: 3 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1868,9 +1868,9 @@ router.get('/gov/chongqing/ljxq/zwgk/:caty', lazyloadRouteHandler('./routes/gov/
router.get('/12379', lazyloadRouteHandler('./routes/12379/index'));

// 鸟哥笔记
router.get('/ngbj', lazyloadRouteHandler('./routes/niaogebiji/index'));
router.get('/ngbj/today', lazyloadRouteHandler('./routes/niaogebiji/today'));
router.get('/ngbj/cat/:cat', lazyloadRouteHandler('./routes/niaogebiji/cat'));
// router.get('/ngbj', lazyloadRouteHandler('./routes/niaogebiji/index'));
// router.get('/ngbj/today', lazyloadRouteHandler('./routes/niaogebiji/today'));
// router.get('/ngbj/cat/:cat', lazyloadRouteHandler('./routes/niaogebiji/cat'));

// 梅花网
router.get('/meihua/shots/:caty', lazyloadRouteHandler('./routes/meihua/shots'));
Expand Down
86 changes: 0 additions & 86 deletions lib/routes/niaogebiji/cat.js

This file was deleted.

40 changes: 0 additions & 40 deletions lib/routes/niaogebiji/index.js

This file was deleted.

29 changes: 0 additions & 29 deletions lib/routes/niaogebiji/today.js

This file was deleted.

53 changes: 53 additions & 0 deletions lib/v2/niaogebiji/cat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const categoryId = ctx.params.cat;
const link = `https://www.niaogebiji.com/cat/${categoryId}`;

const response = await got(link);
const $ = cheerio.load(response.data);
const catName = $('h1').text();

const articles = $('div.articleBox.clearfix')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.articleTitle').text().trim(),
description: item.find('.articleContentInner').text().trim(),
author: item.find('.author').text().trim(),
link: new URL(item.find('a').first().attr('href'), link).href,
category: [
...item
.find('.art_tag')
.toArray()
.map((tag) => $(tag).text().trim()),
catName,
],
};
});

const items = await Promise.all(
articles.map((element) =>
ctx.cache.tryGet(element.link, async () => {
const response = await got(element.link);
const $ = cheerio.load(response.data);

element.pubDate = timezone(parseDate($('.writeTime3').text().trim()), 8);
element.description = $('.pc_content').html();

return element;
})
)
);

ctx.state.data = {
title: $('head title').text(),
description: $('head meta[name="description"]').attr('content'),
link,
item: items,
};
};
41 changes: 41 additions & 0 deletions lib/v2/niaogebiji/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const baseUrl = 'https://www.niaogebiji.com';
const { data: response } = await got(`${baseUrl}/pc/index/getMoreArticle`);

if (response.return_code !== '200') {
throw Error(response.return_msg);
}

const postList = response.return_data.map((item) => ({
title: item.title,
description: item.summary,
author: item.author,
pubDate: parseDate(item.published_at, 'X'),
updated: parseDate(item.updated_at, 'X'),
category: [item.catname, ...item.tag_list],
link: new URL(item.link, baseUrl).href,
}));

const result = await Promise.all(
postList.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

item.description = $('.pc_content').html();

return item;
})
)
);

ctx.state.data = {
title: '鸟哥笔记',
link: baseUrl,
item: result,
};
};
6 changes: 6 additions & 0 deletions lib/v2/niaogebiji/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'': ['WenryXu'],
'/': ['WenryXu'],
'/cat/:cat': ['cKotoriKat'],
'/today': ['KotoriK'],
};
25 changes: 25 additions & 0 deletions lib/v2/niaogebiji/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
'niaogebiji.com': {
_name: '鸟哥笔记',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/new-media#niao-ge-bi-ji',
source: ['/'],
target: '/niaogebiji',
},
{
title: '今日事',
docs: 'https://docs.rsshub.app/new-media#niao-ge-bi-ji',
source: ['/', '/bulletin'],
target: '/niaogebiji',
},
{
title: '分类目录',
docs: 'https://docs.rsshub.app/new-media#niao-ge-bi-ji',
source: ['/cat/:cat'],
target: '/niaogebiji/cat/:cat',
},
],
},
};
5 changes: 5 additions & 0 deletions lib/v2/niaogebiji/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/', require('./index'));
router.get('/cat/:cat', require('./cat'));
router.get('/today', require('./today'));
};
34 changes: 34 additions & 0 deletions lib/v2/niaogebiji/today.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const response = await got({
method: 'post',
url: 'https://www.niaogebiji.com/pc/bulletin/index',
form: {
page: 1,
pub_time: '',
isfromajax: 1,
},
});

if (response.data.return_code !== '200') {
throw Error(response.data.return_msg);
}

const data = response.data.return_data;

ctx.state.data = {
title: '鸟哥笔记-今日事',
link: 'https://www.niaogebiji.com/bulletin',
item: data.map((item) => ({
title: item.title,
description: item.content,
link: item.url,
pubDate: parseDate(item.pub_time, 'X'),
updated: parseDate(item.updated_at, 'X'),
category: item.seo_keywords.split(','),
author: item.user_info.nickname,
})),
};
};
Loading

0 comments on commit cfe8569

Please sign in to comment.