From f4c0c98fa5f975e9e5ed8e00bd9cecafee405232 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 12 Nov 2024 10:59:05 -0800 Subject: [PATCH] feat(route): vertikal (#17561) * feat(route): vertikal * fix(route/vertikal): standardize title string quotes in latest.ts --- lib/routes/vertikal/latest.ts | 73 ++++++++++++++++++++++++++++++++ lib/routes/vertikal/namespace.ts | 7 +++ 2 files changed, 80 insertions(+) create mode 100644 lib/routes/vertikal/latest.ts create mode 100644 lib/routes/vertikal/namespace.ts diff --git a/lib/routes/vertikal/latest.ts b/lib/routes/vertikal/latest.ts new file mode 100644 index 00000000000000..d7e765147a4814 --- /dev/null +++ b/lib/routes/vertikal/latest.ts @@ -0,0 +1,73 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import * as cheerio from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/latest', + categories: ['new-media'], + example: '/vertikal/latest', + radar: [ + { + source: ['vertikal.net/en/news', 'vertikal.net'], + }, + ], + name: 'News Archive', + maintainers: ['TonyRL'], + handler, + url: 'vertikal.net/en/news', +}; + +const baseUrl = 'https://vertikal.net'; + +async function handler() { + const response = await ofetch(`${baseUrl}/en/homepage/async-news-loader`, { + query: { + perPage: 24, + page: 1, + }, + }); + const $ = cheerio.load(response); + + const list = $('.grid__column') + .toArray() + .map((item) => { + const $item = $(item); + return { + title: $item.find('.news-teaser__title').text(), + link: `${baseUrl}${$item.find('.news-teaser').attr('href')}`, + pubDate: parseDate($item.find('.news-teaser__date').text(), 'DD.MM.YYYY'), + description: $item.find('.news-teaser__text').text(), + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = cheerio.load(response); + + const content = $('.newsentry'); + + item.category = content + .find('.newsentry__tags a') + .toArray() + .map((tag) => $(tag).text().trim()); + + content.find('.newsentry__date, .newsentry__title, .lazyimage-placeholder, .newsentry__tags, .newsentry__share, .newsentry__comments, .newsentry__write-comment').remove(); + + item.description = content.html(); + + return item; + }) + ) + ); + + return { + title: 'News Archive | Vertikal.net', + link: `${baseUrl}/en/news`, + image: `${baseUrl}/apple-touch-icon-152x152.png`, + item: items, + }; +} diff --git a/lib/routes/vertikal/namespace.ts b/lib/routes/vertikal/namespace.ts new file mode 100644 index 00000000000000..92bb61b7b0697b --- /dev/null +++ b/lib/routes/vertikal/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Vertikal.net', + url: 'vertikal.net', + lang: 'en', +};