forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): hinatazaka46 blog support id params (DIYgod#12700)
* fix(route): page field change fixes * feat: add route info * feat: migrate to route v2 * feat: support id param * fix(route): news page field change fixes
- Loading branch information
1 parent
ab24f40
commit cdd1170
Showing
6 changed files
with
198 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
'/news': ['crispgm', 'akashigakki'], | ||
'/blog': ['nwindz', 'akashigakki'], | ||
'/blog/:id?': ['nwindz', 'akashigakki'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const rootUrl = 'https://www.hinatazaka46.com'; | ||
const currentUrl = `${rootUrl}/s/official/news/list`; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: 'https://www.hinatazaka46.com/s/official/news/list', | ||
headers: { | ||
Referer: 'http://www.hinatazaka46.com/', | ||
}, | ||
url: currentUrl, | ||
}); | ||
|
||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
const list = $('main div.l-maincontents--news ul.p-news__list li'); | ||
const $ = cheerio.load(response.data); | ||
|
||
let items = $('.p-news__list .p-news__item a') | ||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.find('.c-news__text').text(), | ||
link: `${rootUrl}${item.attr('href').split('?')[0]}`, | ||
pubDate: parseDate(item.find('.c-news__date').text()), | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.description = content('.p-article__text').html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
allowEmpty: true, | ||
title: '日向坂46官网 NEWS', | ||
link: 'http://www.hinatazaka46.com/news/', | ||
item: | ||
list && | ||
list | ||
.map((index, item) => { | ||
item = $(item); | ||
return { | ||
title: item.find('a p.c-news__text').first().text(), | ||
link: item.find('a').attr('href'), | ||
pubDate: item.find('a time.c-news__date').first().text(), | ||
}; | ||
}) | ||
.get(), | ||
title: $('title').text(), | ||
link: currentUrl, | ||
item: items, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = function (router) { | ||
router.get('/news', require('./news')); | ||
router.get('/blog', require('./blog')); | ||
router.get('/blog/:id?', require('./blog')); | ||
}; |