From e92e5c1adb2a5afc7b6482bfe9103327cff622c7 Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 3 May 2024 22:50:55 -0700 Subject: [PATCH] feat(route): digitalcameraworld (#15461) * feat(route): digitalcameraworld * chore: use cheerio to parse rss url --- lib/routes/digitalcameraworld/namespace.ts | 6 +++ lib/routes/digitalcameraworld/news.ts | 61 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 lib/routes/digitalcameraworld/namespace.ts create mode 100644 lib/routes/digitalcameraworld/news.ts diff --git a/lib/routes/digitalcameraworld/namespace.ts b/lib/routes/digitalcameraworld/namespace.ts new file mode 100644 index 000000000..287b9be9b --- /dev/null +++ b/lib/routes/digitalcameraworld/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Digital Camera World', + url: 'digitalcameraworld.com', +}; diff --git a/lib/routes/digitalcameraworld/news.ts b/lib/routes/digitalcameraworld/news.ts new file mode 100644 index 000000000..21ce68e7f --- /dev/null +++ b/lib/routes/digitalcameraworld/news.ts @@ -0,0 +1,61 @@ +import { Route } from '@/types'; +import { load } from 'cheerio'; +import { ofetch } from 'ofetch'; +import { parseDate } from '@/utils/parse-date'; +const host = 'https://www.digitalcameraworld.com'; +export const route: Route = { + path: '/news', + categories: ['new-media'], + example: '/digitalcameraworld/news', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['digitalcameraworld.com/'], + }, + ], + name: 'News', + maintainers: ['EthanWng97'], + handler, +}; + +async function handler() { + const rssUrl = `${host}/feeds.xml`; + + const response = await ofetch(rssUrl); + + const $ = load(response, { + xmlMode: true, + }); + + const items = $('item') + .toArray() + .map((item) => { + item = $(item); + let description = item.find('dc\\:content').text(); + description = $('
').html(description); + description.find('.vanilla-image-block').removeAttr('style'); + description.find('.fancy-box').remove(); + + return { + title: item.find('title').text(), + pubDate: parseDate(item.find('pubDate').text()), + link: item.find('link').text(), + description: description.html(), + }; + }); + + return { + title: 'Digital Camera World', + link: host, + description: 'Camera news, reviews and features', + item: items, + }; +}