fix(route): nogizaka46/news website layout update and refactor to V2 (#9131)

This commit is contained in:
Fatpandac 2022-02-17 20:10:39 +08:00 committed by GitHub
parent a42dce573c
commit ccd6b3a26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 37 deletions

View File

@ -1191,7 +1191,7 @@ Supported sub-sites:
### 乃木坂 46 新闻
<Route author="crispgm" example="/nogizaka46/news" path="/nogizaka46/news" />
<Route author="crispgm Fatpandac" example="/nogizaka46/news" path="/nogizaka46/news" />
### 欅坂 46 新闻

View File

@ -1960,7 +1960,6 @@ router.get('/kaiyan/index', lazyloadRouteHandler('./routes/kaiyan/index'));
// 坂道系列资讯
// 坂道系列官网新闻
router.get('/nogizaka46/news', lazyloadRouteHandler('./routes/nogizaka46/news'));
router.get('/keyakizaka46/news', lazyloadRouteHandler('./routes/keyakizaka46/news'));
router.get('/hinatazaka46/news', lazyloadRouteHandler('./routes/hinatazaka46/news'));
router.get('/keyakizaka46/blog', lazyloadRouteHandler('./routes/keyakizaka46/blog'));

View File

@ -1,35 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'http://www.nogizaka46.com/news/',
headers: {
Referer: 'http://www.nogizaka46.com/',
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('#news #sheet div.left div.padding ul li');
ctx.state.data = {
allowEmpty: true,
title: '乃木坂46官网 NEWS',
link: 'http://www.nogizaka46.com/news/',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('.title strong a').first().text(),
description: item.find('.summary').first().text(),
link: item.find('.title strong a').attr('href'),
pubDate: item.find('.date').first().text(),
};
})
.get(),
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/news': ['crispgm', 'Fatpandac'],
};

30
lib/v2/nogizaka46/news.js Normal file
View File

@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 25;
const response = await got({
method: 'get',
url: 'https://www.nogizaka46.com/s/n46/api/list/news',
headers: {
Referer: 'http://www.nogizaka46.com/',
},
});
const data = JSON.parse(response.data.match(/res\((.*)\);/)[1]).data;
const items = data.slice(0, limit).map((item) => ({
title: item.title,
link: item.link_url,
description: item.text,
pubDate: parseDate(item.date),
category: item.cate,
}));
ctx.state.data = {
allowEmpty: true,
title: '乃木坂46官网 NEWS',
link: 'http://www.nogizaka46.com/news/',
item: items,
};
};

View File

@ -0,0 +1,13 @@
module.exports = {
'nogizaka46.com': {
_name: '乃木坂46',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/new-media.html#ban-dao-xi-lie-guan-wang-zi-xun-nai-mu-ban-46-xin-wen',
source: ['/', '/s/n46/news/list'],
target: '/nogizaka46/news',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news', require('./news'));
};