diff --git a/lib/v2/kamen-rider-official/maintainer.js b/lib/v2/kamen-rider-official/maintainer.js new file mode 100644 index 00000000000000..d4350891fda653 --- /dev/null +++ b/lib/v2/kamen-rider-official/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category?': ['nczitzk'], +}; diff --git a/lib/v2/kamen-rider-official/news.js b/lib/v2/kamen-rider-official/news.js new file mode 100644 index 00000000000000..f514d35a71c454 --- /dev/null +++ b/lib/v2/kamen-rider-official/news.js @@ -0,0 +1,110 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const { category } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50; + + const rootUrl = 'https://www.kamen-rider-official.com'; + const apiUrl = new URL('api/v1/news_articles', rootUrl).href; + const currentUrl = new URL(`news_articles/${category ? `?category=${category}` : ''}`, rootUrl).href; + + const { data: currentResponse } = await got(currentUrl); + + const buildId = currentResponse.match(/"buildId":"(\w+)"/)[1]; + + const apiCategoryUrl = new URL(`_next/data/${buildId}/news_articles.json`, rootUrl).href; + + const { data: categoryResponse } = await got(apiCategoryUrl); + + const id = categoryResponse.pageProps.categoryIds[category]; + + const { data: response } = await got(apiUrl, { + searchParams: { + category_id: id, + limit, + offset: 0, + }, + }); + + let items = response.news_articles.slice(0, limit).map((item) => ({ + title: item.list_title, + link: new URL(item.path, rootUrl).href, + description: art(path.join(__dirname, 'templates/description.art'), { + image: item.list_image_path + ? { + src: new URL(item.list_image_path, rootUrl).href, + alt: item.list_title, + } + : undefined, + }), + author: item.author, + category: [item.category_name, item.category_2_name].filter((c) => c), + guid: `kamen-rider-official-${item.id}`, + pubDate: parseDate(item.release_date), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + content('a.c-button').each(function () { + content(this).parent().remove(); + }); + + content('img').each(function () { + content(this).replaceWith( + art(path.join(__dirname, 'templates/description.art'), { + image: { + src: content(this).prop('src'), + }, + }) + ); + }); + + item.title = content('h1.p-post__title').text() || item.title; + item.description = content('main.p-post__main').html(); + item.author = content('div.p-post__responsibility p') + .toArray() + .map((a) => content(a).text()) + .join(' / '); + item.category = Array.from( + new Set( + [ + ...item.category, + ...content('ul.p-post__categories li a.p-post__category') + .toArray() + .map((c) => content(c).text().trim()), + ].filter((c) => c) + ) + ); + + return item; + }) + ) + ); + + const $ = cheerio.load(currentResponse); + + const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; + + ctx.state.data = { + item: items, + title: `${$('title').text().split(/ー/)[0]}${category ? ` - ${category}` : ''}`, + link: currentUrl, + description: $('meta[property="og:description"]').prop('content'), + language: $('html').prop('lang'), + image: $('meta[property="og:image"]').prop('content'), + icon, + logo: icon, + subtitle: $('meta[property="keywords"]').prop('content'), + author: $('meta[property="og:site_name"]').prop('content'), + allowEmpty: true, + }; +}; diff --git a/lib/v2/kamen-rider-official/radar.js b/lib/v2/kamen-rider-official/radar.js new file mode 100644 index 00000000000000..5590dad332edb8 --- /dev/null +++ b/lib/v2/kamen-rider-official/radar.js @@ -0,0 +1,18 @@ +module.exports = { + 'kamen-rider-official.com': { + _name: '仮面ライダ', + '.': [ + { + title: '最新情報', + docs: 'https://docs.rsshub.app/routes/new-media#fan-mian-%E3%83%A9%E3%82%A4%E3%83%80-zui-xin-qing-bao', + source: ['/news_articles'], + target: (params, url) => { + url = new URL(url); + const category = url.searchParams.get('category'); + + return `/kamen-rider-official/news${category ? `/${category}` : ''}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/kamen-rider-official/router.js b/lib/v2/kamen-rider-official/router.js new file mode 100644 index 00000000000000..1b7e3945024095 --- /dev/null +++ b/lib/v2/kamen-rider-official/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news/:category?', require('./news')); +}; diff --git a/lib/v2/kamen-rider-official/templates/description.art b/lib/v2/kamen-rider-official/templates/description.art new file mode 100644 index 00000000000000..a56b27f6eda4e4 --- /dev/null +++ b/lib/v2/kamen-rider-official/templates/description.art @@ -0,0 +1,10 @@ +{{ if image }} +
+ {{ image.alt }} +
+{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/new-media.md b/website/docs/routes/new-media.md index 37c117487081a5..1eb05697ad02f8 100644 --- a/website/docs/routes/new-media.md +++ b/website/docs/routes/new-media.md @@ -2794,6 +2794,47 @@ Type 栏目: +## 仮面ライダ {#fan-mian-%E3%83%A9%E3%82%A4%E3%83%80} + +### 最新情報 {#fan-mian-%E3%83%A9%E3%82%A4%E3%83%80-zui-xin-qing-bao} + + + +| Category | +| -------------------------------------- | +| すべて | +| テレビ | +| 映画・Vシネマ等 | +| Blu-ray・DVD、配信等 | +| 20作記念グッズ・東映EC商品 | +| 石ノ森章太郎生誕80周年記念商品 | +| 玩具・カード | +| 食品・飲料・菓子 | +| 子供生活雑貨 | +| アパレル・大人向け雑貨 | +| フィギュア・ホビー・一番くじ・プライズ | +| ゲーム・デジタル | +| 雑誌・書籍・漫画 | +| 音楽 | +| 映像 | +| イベント | +| ホテル・レストラン等 | +| キャンペーン・タイアップ等 | +| その他 | +| KAMEN RIDER STORE | +| THE鎧武祭り | +| 鎧武外伝 | +| 仮面ライダーリバイス | +| ファイナルステージ | +| THE50周年展 | +| 風都探偵 | +| 仮面ライダーギーツ | +| 仮面ライダーアウトサイダーズ | +| 仮面ライダーガッチャード | +| 仮面ライダーBLACK SUN | + + + ## 飞雪娱乐网 {#fei-xue-yu-le-wang}