feat(route): add coolidge (#19984)
* feat: add coolidge film guide * feat: add coolidge news route * refactor: use kebab case * fix: change category
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'Coolidge Corner Theatre',
|
||||
url: 'coolidge.org',
|
||||
lang: 'en',
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{{if image}}
|
||||
<p><img src="{{ image }}"></p>
|
||||
{{/if}}
|
||||
<p>{{ intro }}</p>
|
||||
Reference in New Issue
Block a user