Skip to content

Commit 1f3b11c

Browse files
authored
feat(route): add lancedb blog route (#20886)
* feat: add lancedb blog * resolve comment
1 parent 26eab36 commit 1f3b11c

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

lib/routes/lancedb/blog.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { load } from 'cheerio';
2+
import type { Context } from 'hono';
3+
4+
import type { Data, Route } from '@/types';
5+
import { ViewType } from '@/types';
6+
import ofetch from '@/utils/ofetch';
7+
import { parseDate } from '@/utils/parse-date';
8+
9+
export const handler = async (ctx: Context): Promise<Data> => {
10+
const { category } = ctx.req.param();
11+
const baseUrl = 'https://lancedb.com';
12+
const url = category ? `${baseUrl}/blog/category/${category}` : `${baseUrl}/blog`;
13+
const response = await ofetch(url);
14+
const $ = load(response);
15+
16+
const items = $('article')
17+
.toArray()
18+
.map((el) => {
19+
const $el = $(el);
20+
const title = $el.find('h2 a').text().trim();
21+
const link = $el.find('h2 a').attr('href');
22+
23+
const description = $el.find('p.post-description').text().trim();
24+
const meta = $el.find('.post-meta').text().trim().replaceAll(/\s+/g, ' ');
25+
const [cat, author, dateStr] = meta.split(' / ');
26+
const pubDate = dateStr ? parseDate(dateStr) : undefined;
27+
28+
return {
29+
title,
30+
link,
31+
description,
32+
pubDate,
33+
author,
34+
category: cat ? [cat] : [],
35+
};
36+
});
37+
38+
return {
39+
title: `LanceDB Blog${category ? ` - ${category}` : ''}`,
40+
link: url,
41+
item: items,
42+
};
43+
};
44+
45+
export const route: Route = {
46+
path: '/blog/:category?',
47+
name: 'Blog',
48+
url: 'lancedb.com/blog',
49+
maintainers: ['HUSTERGS'],
50+
example: '/lancedb/blog',
51+
parameters: {
52+
category: 'filter blog post by category, return all posts if not specified',
53+
},
54+
description: undefined,
55+
categories: ['programming'],
56+
features: {
57+
requireConfig: false,
58+
requirePuppeteer: false,
59+
antiCrawler: false,
60+
supportBT: false,
61+
supportPodcast: false,
62+
supportScihub: false,
63+
},
64+
radar: [
65+
{
66+
source: ['lancedb.com/blog', 'lancedb.com/blog/category/:category'],
67+
target: '/blog/:category',
68+
},
69+
],
70+
view: ViewType.Articles,
71+
handler,
72+
};

lib/routes/lancedb/namespace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Namespace } from '@/types';
2+
3+
export const namespace: Namespace = {
4+
name: 'LanceDB',
5+
url: 'lancedb.com',
6+
description: '',
7+
lang: 'en',
8+
};

0 commit comments

Comments
 (0)