From 84ec717db9bf954ce72f3deaae6ebb087e2f30af Mon Sep 17 00:00:00 2001 From: Dmitry Sukhodoyev Date: Sat, 1 Mar 2025 23:38:34 +0500 Subject: [PATCH] feat(route): add forklog route (#18477) --- lib/routes/forklog/index.ts | 72 +++++++++++++++++++++++++++++++++ lib/routes/forklog/namespace.ts | 7 ++++ 2 files changed, 79 insertions(+) create mode 100644 lib/routes/forklog/index.ts create mode 100644 lib/routes/forklog/namespace.ts diff --git a/lib/routes/forklog/index.ts b/lib/routes/forklog/index.ts new file mode 100644 index 000000000..d00c3fdb0 --- /dev/null +++ b/lib/routes/forklog/index.ts @@ -0,0 +1,72 @@ +import { Route } from '@/types'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/news', + categories: ['finance'], + example: '/forklog/news', + radar: [ + { + source: ['forklog.com/news'], + target: '/news', + }, + ], + name: 'Новости', + maintainers: ['raven428'], + handler, + url: 'forklog.com/news', +}; + +async function handler() { + const response = await got( + 'https://forklog.com/wp-content/themes/forklogv2/ajax/getPosts.php', { + method: 'POST', + headers: { 'x-requested-with': 'XMLHttpRequest' }, + form: { action: 'getPostsByCategory', postperpage: '333' }, + } + ); + const items = JSON.parse(response.body).map((post) => { + const link = post.link; + const title = (post.title || post.text?.post_title)?.trim(); + const description = post.text?.post_content.trim(); + const author = post.author_name.trim(); + let pubDate; + if (post.text?.post_date_gmt) { + pubDate = timezone(parseDate(post.text.post_date_gmt), +1); + } else if (post.text?.post_date) { + pubDate = timezone(parseDate(post.text.post_date), +4); + } else if (post.date) { + pubDate = timezone(parseDate(post.date, 'DD.MM.YYYY HH:mm'), +4); + } + const imageSrc = post.image || post.image_mobile; + const views = post.views; + return { + link, + title, + author, + pubDate, + description, + category: ['news', 'crypto', 'finance'], + ...(imageSrc ? { + media: { + thumbnail: { + url: imageSrc, + width: 250, + height: 250, + } + }, + } : {}), + extra: { + views, + }, + }; + }); + return { + title: 'Forklog – Новости', + link: 'https://forklog.com/news', + description: 'Последние новости из мира блокчейна и криптовалют', + item: items, + }; +} diff --git a/lib/routes/forklog/namespace.ts b/lib/routes/forklog/namespace.ts new file mode 100644 index 000000000..8540d0d6c --- /dev/null +++ b/lib/routes/forklog/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Forklog', + url: 'forklog.com', + lang: 'ru', +};