From ad3ba0304104396c84d0d5027deaffaa79bd5935 Mon Sep 17 00:00:00 2001 From: Noah Manneschmidt Date: Tue, 25 Feb 2025 09:56:01 -0800 Subject: [PATCH] feat(route): add League of Legends patch notes (#18449) --- lib/routes/leagueoflegends/namespace.ts | 8 +++ lib/routes/leagueoflegends/patch-notes.ts | 76 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 lib/routes/leagueoflegends/namespace.ts create mode 100644 lib/routes/leagueoflegends/patch-notes.ts diff --git a/lib/routes/leagueoflegends/namespace.ts b/lib/routes/leagueoflegends/namespace.ts new file mode 100644 index 000000000..68acd3d57 --- /dev/null +++ b/lib/routes/leagueoflegends/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'League of Legends', + url: 'leagueoflegends.com', + categories: ['game'], + lang: 'en', +}; diff --git a/lib/routes/leagueoflegends/patch-notes.ts b/lib/routes/leagueoflegends/patch-notes.ts new file mode 100644 index 000000000..4a32a07dd --- /dev/null +++ b/lib/routes/leagueoflegends/patch-notes.ts @@ -0,0 +1,76 @@ +import { DataItem, Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/patch-notes', + categories: ['game'], + example: '/leagueoflegends/patch-notes', + radar: [ + { + source: ['www.leagueoflegends.com/en-us/news/tags/patch-notes/', 'www.leagueoflegends.com/en-us/news/game-updates/:postSlug'], + }, + ], + name: 'Patch Notes', + maintainers: ['noahm'], + async handler() { + const url = 'https://www.leagueoflegends.com/en-us/news/tags/patch-notes/'; + const response = await got({ + method: 'get', + url, + }); + + const data = response.data; + + const $ = load(data); + const nextData = $('script[id="__NEXT_DATA__"]').text(); + if (!nextData) { + throw new Error('missing next data'); + } + const list: PatchNotesItem[] = JSON.parse(nextData).props.pageProps.page.blades[2].items; + + return { + title: 'League of Legends Patch Notes', + link: url, + item: list.map( + (item): DataItem => ({ + title: item.title, + description: item.description.body, + pubDate: parseDate(item.publishedAt), + link: item.action.payload.url, + guid: item.analytics.contentId, + image: item.media.url, + itunes_item_image: item.media.url, + }) + ), + }; + }, +}; + +// partial type definition of JSON data pre-filled on the page +interface PatchNotesItem { + title: string; + publishedAt: string; + description: { + type: 'html'; + body: string; + }; + media: { + dimensions: { + height: number; + width: number; + }; + mimeType: string; + url: string; + }; + action: { + payload: { + url: string; + }; + type: 'weblink'; + }; + analytics: { + contentId: string; + }; +}