From b4d200c9655d3bcc4e480f563f6d45ed4a8111b8 Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 3 May 2024 08:36:32 -0700 Subject: [PATCH] feat(route): gq (#15454) --- lib/routes/gq/namespace.ts | 6 ++++ lib/routes/gq/news.ts | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 lib/routes/gq/namespace.ts create mode 100644 lib/routes/gq/news.ts diff --git a/lib/routes/gq/namespace.ts b/lib/routes/gq/namespace.ts new file mode 100644 index 000000000..9814d3c32 --- /dev/null +++ b/lib/routes/gq/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'GQ', + url: 'gq.com', +}; diff --git a/lib/routes/gq/news.ts b/lib/routes/gq/news.ts new file mode 100644 index 000000000..b012ff9c3 --- /dev/null +++ b/lib/routes/gq/news.ts @@ -0,0 +1,59 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import parser from '@/utils/rss-parser'; +import { load } from 'cheerio'; +import { ofetch } from 'ofetch'; +const host = 'https://www.gq.com'; +export const route: Route = { + path: '/news', + categories: ['traditional-media'], + example: '/gq/news', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['gq.com/'], + }, + ], + name: 'News', + maintainers: ['EthanWng97'], + handler, +}; + +async function handler() { + const rssUrl = `${host}/feed/rss`; + const feed = await parser.parseURL(rssUrl); + const items = await Promise.all( + feed.items.map((item) => + cache.tryGet(item.link, async () => { + const data = await ofetch(item.link); + const $ = load(data); + const description = $('#main-content'); + description.find('.article-body__footer').remove(); + description.find('[class*="ContentHeaderContributorImage"]').remove(); + description.find('h1').remove(); + return { + title: item.title, + pubDate: item.pubDate, + link: item.link, + category: item.categories, + description: description.html(), + }; + }) + ) + ); + + return { + title: 'GQ', + link: host, + description: `GQ is the global flagship of men's fashion, the arbiter of cool for anyone who sees the world through the lens of taste and style.`, + item: items, + }; +}