diff --git a/lib/routes/devtrium/namespace.ts b/lib/routes/devtrium/namespace.ts new file mode 100644 index 00000000000000..5a2ff90d0e706b --- /dev/null +++ b/lib/routes/devtrium/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Devtrium', + url: 'devtrium.com', +}; diff --git a/lib/routes/devtrium/posts.ts b/lib/routes/devtrium/posts.ts new file mode 100644 index 00000000000000..1a842c14be0b3f --- /dev/null +++ b/lib/routes/devtrium/posts.ts @@ -0,0 +1,55 @@ +import { DataItem, Route } from '@/types'; +import { load } from 'cheerio'; +import { ofetch } from 'ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/', + categories: ['programming'], + example: '/devtrium', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['devtrium.com'], + }, + ], + name: 'Official Blogs', + maintainers: ['Xy2002'], + handler, + url: 'devtrium.com', +}; + +async function handler() { + const items = await fetchPage(); + + return { + title: 'Devtrium', + language: 'en-us', + item: items, + link: 'https://devtrium.com', + }; +} + +async function fetchPage() { + const baseUrl = 'https://devtrium.com'; + const response = await ofetch(baseUrl); + const $ = load(response, { scriptingEnabled: false }); + + // Extract all posts of this page + const data = JSON.parse($('script#__NEXT_DATA__').text()); + const items: DataItem[] = data.props.pageProps.posts.map((post) => ({ + title: post.title, + link: `${baseUrl}/posts/${post.slug}`, + description: post.description, + pubDate: parseDate(post.date), + })); + return items; +}