From 1a971f5f2828ccaf50e2f66ae0b8bd186938464e Mon Sep 17 00:00:00 2001 From: Axojhf <20625305+axojhf@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:45:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AAlovelive=E5=AE=98=E7=BD=91NEWS=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9A=84=E8=B7=AF=E7=94=B1=20(#10478)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加新的路由lovelive-anime * 修改部分debug,添加以符合标准 * Update docs/anime.md Co-authored-by: Tony * Update lib/v2/lovelive-anime/news.js Co-authored-by: Tony * Update lib/v2/lovelive-anime/news.js Co-authored-by: Tony * Update lib/v2/lovelive-anime/news.js Co-authored-by: Tony * Update lib/v2/lovelive-anime/templates/description.art Co-authored-by: Tony * Add en docs Co-authored-by: axojhf --- docs/anime.md | 6 ++ docs/en/anime.md | 6 ++ lib/v2/lovelive-anime/maintainer.js | 3 + lib/v2/lovelive-anime/news.js | 56 +++++++++++++++++++ lib/v2/lovelive-anime/radar.js | 13 +++++ lib/v2/lovelive-anime/router.js | 3 + .../lovelive-anime/templates/description.art | 1 + 7 files changed, 88 insertions(+) create mode 100644 lib/v2/lovelive-anime/maintainer.js create mode 100644 lib/v2/lovelive-anime/news.js create mode 100644 lib/v2/lovelive-anime/radar.js create mode 100644 lib/v2/lovelive-anime/router.js create mode 100644 lib/v2/lovelive-anime/templates/description.art diff --git a/docs/anime.md b/docs/anime.md index 80a99d967..1922e6f0d 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -347,6 +347,12 @@ Sources +## lovelive-anime + +### Love Live 官网最新News + + + ## Mox.moe ### 首頁 diff --git a/docs/en/anime.md b/docs/en/anime.md index 1120f83f9..a43c09e62 100644 --- a/docs/en/anime.md +++ b/docs/en/anime.md @@ -56,6 +56,12 @@ When `posts` is selected as the value of the parameter **source**, the parameter +## lovelive-anime + +### Love Live! Official Website Latest NEWS + + + ## Touhougarakuta ### Articles diff --git a/lib/v2/lovelive-anime/maintainer.js b/lib/v2/lovelive-anime/maintainer.js new file mode 100644 index 000000000..4dc741ff7 --- /dev/null +++ b/lib/v2/lovelive-anime/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:option?': ['axojhf'], +}; diff --git a/lib/v2/lovelive-anime/news.js b/lib/v2/lovelive-anime/news.js new file mode 100644 index 000000000..ec9c987e3 --- /dev/null +++ b/lib/v2/lovelive-anime/news.js @@ -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()}
` + 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, + }; +}; diff --git a/lib/v2/lovelive-anime/radar.js b/lib/v2/lovelive-anime/radar.js new file mode 100644 index 000000000..fa57df0d3 --- /dev/null +++ b/lib/v2/lovelive-anime/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/lovelive-anime/router.js b/lib/v2/lovelive-anime/router.js new file mode 100644 index 000000000..c7bbc2e16 --- /dev/null +++ b/lib/v2/lovelive-anime/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news/:option?', require('./news')); +}; diff --git a/lib/v2/lovelive-anime/templates/description.art b/lib/v2/lovelive-anime/templates/description.art new file mode 100644 index 000000000..6f85ee13f --- /dev/null +++ b/lib/v2/lovelive-anime/templates/description.art @@ -0,0 +1 @@ +{{title}}
\ No newline at end of file