feat(route): add bvisness.me blog route (#20929)
This commit is contained in:
parent
04330df386
commit
685598f0f8
|
|
@ -0,0 +1,43 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
name: 'Blog',
|
||||
categories: ['blog'],
|
||||
maintainers: ['raxod502'],
|
||||
path: '/blog',
|
||||
example: '/bvisness/blog',
|
||||
handler,
|
||||
radar: [
|
||||
{
|
||||
source: ['bvisness.me'],
|
||||
target: '/blog',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const response = await ofetch('https://bvisness.me/');
|
||||
const $ = load(response);
|
||||
|
||||
const items = $('article')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a').first();
|
||||
return {
|
||||
title: a.text(),
|
||||
link: new URL(a.attr('href'), 'https://bvisness.me/').href,
|
||||
pubDate: parseDate(item.find('time').attr('datetime')),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
title: 'Ben Visness Blog',
|
||||
link: 'https://bvisness.me/',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'Ben Visness',
|
||||
url: 'bvisness.me',
|
||||
};
|
||||
Loading…
Reference in New Issue