diff --git a/lib/routes/zed/blog.ts b/lib/routes/zed/blog.ts new file mode 100644 index 0000000000..8f1d3f84bc --- /dev/null +++ b/lib/routes/zed/blog.ts @@ -0,0 +1,75 @@ +import { Route, DataItem, Data, ViewType } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import parser from '@/utils/rss-parser'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/blog', + categories: ['programming'], + example: '/zed/blog', + url: 'zed.dev', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['zed.dev'], + target: '/blog', + }, + ], + name: 'Blog', + maintainers: ['cscnk52'], + handler, + description: 'Provides a better reading experience (full articles) over the official ones.', + view: ViewType.Notifications, +}; + +async function handler() { + const feed = await parser.parseURL('https://zed.dev/blog.rss'); + + const items = await Promise.all( + feed.items.map((item) => + cache.tryGet(item.link as string, async () => { + const data = await ofetch(item.link as string); + const $ = load(data); + + const article = $('article'); + + // clean HTML + article.find('style').remove(); + article.find('[style]').removeAttr('style'); + article.find('[class]').removeAttr('class'); + article.find('[id]').removeAttr('id'); + article.find('[preload]').removeAttr('preload'); + article.find('script').remove(); + article.find('figcaption').remove(); + article.find('aside').remove(); // remove Looking and hiring part + + item.content = article.html() as string; + + return { + title: item.title, + link: item.link, + description: item.content, + pubDate: item.pubDate, + author: item.creator, + } as DataItem; + }) + ) + ); + + return { + title: feed.title, + link: feed.link, + description: feed.description, + item: items, + language: 'en', + } as Data; +} diff --git a/lib/routes/zed/namespace.ts b/lib/routes/zed/namespace.ts new file mode 100644 index 0000000000..64cb0f399d --- /dev/null +++ b/lib/routes/zed/namespace.ts @@ -0,0 +1,7 @@ +import { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Zed', + url: 'zed.dev', + lang: 'en', +};