feat(route): 添加一个lovelive官网NEWS信息获取的路由 (#10478)

* 添加新的路由lovelive-anime

* 修改部分debug,添加以符合标准

* Update docs/anime.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/lovelive-anime/news.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/lovelive-anime/news.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/lovelive-anime/news.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/lovelive-anime/templates/description.art

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Add en docs

Co-authored-by: axojhf <axojhf@foxmail.com>
This commit is contained in:
Axojhf
2022-08-16 18:45:08 +08:00
committed by GitHub
co-authored by Tony axojhf
parent 6b34eb8c57
commit 1a971f5f28
7 changed files with 88 additions and 0 deletions
+6
View File
@@ -347,6 +347,12 @@ Sources
</Route>
## lovelive-anime
### Love Live 官网最新News
<Route author="axojhf" example="/lovelive-anime/news" path="/lovelive-anime/news/:option?" :paramsDesc="['`option` 为 `detail` 时抓取全文']" />
## Mox.moe
### 首頁
+6
View File
@@ -56,6 +56,12 @@ When `posts` is selected as the value of the parameter **source**, the parameter
</RouteEn>
## lovelive-anime
### Love Live! Official Website Latest NEWS
<RouteEn author="axojhf" example="/lovelive-anime/news" path="/lovelive-anime/news/:option?" :paramsDesc="['Crawl full text when `option` is `detail`.']" />
## Touhougarakuta
### Articles
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/news/:option?': ['axojhf'],
};
+56
View File
@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const path = require('path');
const { art } = require('@/utils/render');
const renderDescription = (desc) => art(path.join(__dirname, 'templates/description.art'), desc);
module.exports = async (ctx) => {
const rootUrl = 'https://www.lovelive-anime.jp/news/';
const response = await got(rootUrl);
const $ = cheerio.load(response.data);
const pageFace = $('div.c-card.p-colum__box')
.map((_, item) => {
item = $(item);
return {
link: item.find('a.c-card__head').attr('href'),
pubDate: item.find('span.c-card__date').text(),
title: item.find('div.c-card__title').text(),
// description: `${item.find('div.c-card__title').text()}<br><img src="${item.find('a.c-card__head > div > figure > img').attr('src')}">`
description: renderDescription({
title: item.find('div.c-card__title').text(),
imglink: item.find('a.c-card__head > div > figure > img').attr('src'),
}),
};
})
.get();
let items = pageFace;
if (ctx.params.option === 'detail') {
items = await Promise.all(
pageFace.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResp = await got(item.link);
const $ = cheerio.load(detailResp.data);
const content = $('div.p-page__detail.p-article');
for (const v of content.find('img')) {
v.attribs.src = 'https://www.lovelive-anime.jp' + v.attribs.src;
}
item.description = content.html();
return item;
})
)
);
}
ctx.state.data = {
title: 'lovelive official website news',
link: 'https://www.lovelive-anime.jp/news/',
item: items,
};
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'lovelive-anime.jp': {
_name: 'Love Live 官网',
www: [
{
title: '最新NEWS',
docs: 'https://docs.rsshub.app/anime.html#lovelive-anime',
source: ['/'],
target: '/lovelive-anime/news',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/news/:option?', require('./news'));
};
@@ -0,0 +1 @@
{{title}}<br><img src="{{imglink}}">