From 4e087413004ed0323653614a9c49e10e7cee63dc Mon Sep 17 00:00:00 2001 From: Tsung-Han Yu <14802181+johan456789@users.noreply.github.com> Date: Sat, 6 Sep 2025 07:40:45 +0800 Subject: [PATCH] feat(route): add coolidge (#19984) * feat: add coolidge film guide * feat: add coolidge news route * refactor: use kebab case * fix: change category --- lib/routes/coolidge/film-guide.ts | 62 ++++++++++++++++++ lib/routes/coolidge/namespace.ts | 7 ++ lib/routes/coolidge/news.ts | 65 +++++++++++++++++++ lib/routes/coolidge/templates/description.art | 4 ++ 4 files changed, 138 insertions(+) create mode 100644 lib/routes/coolidge/film-guide.ts create mode 100644 lib/routes/coolidge/namespace.ts create mode 100644 lib/routes/coolidge/news.ts create mode 100644 lib/routes/coolidge/templates/description.art diff --git a/lib/routes/coolidge/film-guide.ts b/lib/routes/coolidge/film-guide.ts new file mode 100644 index 000000000..599089a61 --- /dev/null +++ b/lib/routes/coolidge/film-guide.ts @@ -0,0 +1,62 @@ +import { type Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; +import path from 'node:path'; + +const handler = async () => { + const link = 'https://coolidge.org/film-guide'; + const html = await ofetch(link); + const $ = load(html); + + const container = $('#block-coolidge-content > article > div.node__content > div').first(); + + const cover = container.find('p').eq(0).find('img').first().attr('src'); + const title = container.find('p').eq(1).text().trim(); + const description = container.find('p').eq(2).text().trim(); + const linkEl = container.find('a').first(); + const itemLink = linkEl.attr('href'); + + const absoluteCover = cover ? new URL(cover, link).href : undefined; + const absoluteItemLink = itemLink ? new URL(itemLink, link).href : undefined; + + const rendered = art(path.join(__dirname, 'templates/description.art'), { + image: absoluteCover, + intro: description, + }); + + return { + title: 'Coolidge Corner Theatre - Film Guide', + link, + description: 'Film Guide', + item: [ + { + title, + description: rendered, + link: absoluteItemLink ?? link, + guid: absoluteItemLink ?? absoluteCover ?? link, + }, + ], + }; +}; + +export const route: Route = { + path: '/film-guide', + name: 'Film Guide', + url: 'coolidge.org/film-guide', + maintainers: ['johan456789'], + example: '/coolidge/film-guide', + categories: ['blog'], + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + handler, +}; + + diff --git a/lib/routes/coolidge/namespace.ts b/lib/routes/coolidge/namespace.ts new file mode 100644 index 000000000..0ab962226 --- /dev/null +++ b/lib/routes/coolidge/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Coolidge Corner Theatre', + url: 'coolidge.org', + lang: 'en', +}; diff --git a/lib/routes/coolidge/news.ts b/lib/routes/coolidge/news.ts new file mode 100644 index 000000000..52508736a --- /dev/null +++ b/lib/routes/coolidge/news.ts @@ -0,0 +1,65 @@ +import { type Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; +import path from 'node:path'; + +const handler = async () => { + const link = 'https://coolidge.org/about-us/news-media'; + const html = await ofetch(link); + const $ = load(html); + + const container = $('#block-coolidge-content > div > div > div.view-content').first(); + const elements = container.find('div.news-item').toArray(); + + const items = elements.map((el) => { + const element = $(el); + + const titleEl = element.find('h2.news-item__title > a').first(); + const title = titleEl.text().trim(); + const href = titleEl.attr('href'); + const descriptionText = element.find('div.news-item__content > p').first().text().trim(); + const imageSrc = element.find('div.news-item__image img').first().attr('src'); + + const absoluteLink = href ? new URL(href, link).href : undefined; + const absoluteImage = imageSrc ? new URL(imageSrc, link).href : undefined; + + const rendered = art(path.join(__dirname, 'templates/description.art'), { + image: absoluteImage, + intro: descriptionText, + }); + + return { + title, + description: rendered, + link: absoluteLink ?? link, + guid: absoluteLink ?? absoluteImage ?? title, + }; + }); + + return { + title: 'Coolidge Corner Theatre - News', + link, + description: 'News', + item: items, + }; +}; + +export const route: Route = { + path: '/news', + name: 'News', + url: 'coolidge.org/about-us/news-media', + maintainers: ['johan456789'], + example: '/coolidge/news', + categories: ['blog'], + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + handler, +}; diff --git a/lib/routes/coolidge/templates/description.art b/lib/routes/coolidge/templates/description.art new file mode 100644 index 000000000..3afa8351d --- /dev/null +++ b/lib/routes/coolidge/templates/description.art @@ -0,0 +1,4 @@ +{{if image}} +

+{{/if}} +

{{ intro }}