feat(route/visualstudio/code): add Visual Studio Code blog route (#19149)
* feat(route/vscode): add Visual Studio Code blog route * fix: fix name * fix: use `visualstudio` namespace * fix: add missing config * fix: fix feed description * fix: Only use template literals when necessary Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: remove title and time in description ---------
This commit is contained in:
parent
bf0a061d5d
commit
380a6db238
|
|
@ -0,0 +1,67 @@
|
|||
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: '/code/blog',
|
||||
categories: ['programming'],
|
||||
example: '/visualstudio/code/blog',
|
||||
url: 'code.visualstudio.com',
|
||||
parameters: {},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['code.visualstudio.com/'],
|
||||
target: '/code/blog',
|
||||
},
|
||||
],
|
||||
name: 'Code 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://code.visualstudio.com/feed.xml');
|
||||
|
||||
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);
|
||||
|
||||
// remove title and time
|
||||
$('main h1').first().remove();
|
||||
$('main p').first().remove();
|
||||
|
||||
item.content = $('main').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;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'Visual Studio',
|
||||
url: 'visualstudio.com',
|
||||
lang: 'en',
|
||||
};
|
||||
Loading…
Reference in New Issue