Skip to content

Commit

Permalink
feat(route): vertikal (DIYgod#17561)
Browse files Browse the repository at this point in the history
* feat(route): vertikal

* fix(route/vertikal): standardize title string quotes in latest.ts
  • Loading branch information
TonyRL authored Nov 12, 2024
1 parent 40d4a1f commit f4c0c98
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
73 changes: 73 additions & 0 deletions lib/routes/vertikal/latest.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
7 changes: 7 additions & 0 deletions lib/routes/vertikal/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Vertikal.net',
url: 'vertikal.net',
lang: 'en',
};

0 comments on commit f4c0c98

Please sign in to comment.