Skip to content

Commit 5d03607

Browse files
committed
feat(route): add burlington.ca
1 parent e3c86d8 commit 5d03607

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

lib/routes/burlington.ca/index.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type { Route } from '@/types';
2+
import ofetch from '@/utils/ofetch';
3+
import { load } from 'cheerio';
4+
import type { Context } from 'hono';
5+
6+
export const route: Route = {
7+
path: '/:lang/:module',
8+
categories: ['government'],
9+
example: '/burlington.ca/en/FestivalsEvents',
10+
parameters: {
11+
lang: 'language',
12+
module: 'module',
13+
},
14+
features: {
15+
requireConfig: false,
16+
requirePuppeteer: false,
17+
antiCrawler: false,
18+
supportBT: false,
19+
supportPodcast: false,
20+
supportScihub: false,
21+
},
22+
radar: [
23+
{
24+
source: ['www.burlington.ca/Modules/News/:lang/:module'],
25+
target: '/:lang/:module',
26+
},
27+
],
28+
name: 'Burlington.ca',
29+
maintainers: ['elibroftw'],
30+
handler,
31+
description: 'Get news and events from Burlington.ca modules',
32+
};
33+
34+
async function handler(ctx: Context) {
35+
const { lang, module } = ctx.req.param();
36+
const url = `https://www.burlington.ca/Modules/News/${lang}/${module}`;
37+
38+
const response = await ofetch(url);
39+
const $ = load(response);
40+
41+
let items = $('div.blogItem')
42+
.toArray()
43+
.map((element) => {
44+
const $item = $(element);
45+
const title = $item.find('h2 a').text().trim();
46+
const relativeLink = $item.find('h2 a').attr('href');
47+
if (!relativeLink) {
48+
return null;
49+
}
50+
const link = relativeLink.startsWith('http') ? relativeLink : `https://www.burlington.ca${relativeLink}`;
51+
const dateStr = $item.find('.blogPostDate p').text().trim().replace('Posted on ', '');
52+
const description = $item.find('div.blogItem-contentContainer').html();
53+
54+
return {
55+
title,
56+
link,
57+
pubDate: dateStr,
58+
description,
59+
guid: link,
60+
};
61+
})
62+
.filter((item): item is any => !!item);
63+
64+
items = items.filter((item) => item.title && item.link);
65+
66+
return {
67+
title: $('title').text() || `Burlington.ca ${module}`,
68+
link: url,
69+
item: items,
70+
};
71+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Namespace } from '@/types';
2+
3+
export const namespace: Namespace = {
4+
name: 'Burlington.ca',
5+
url: 'burlington.ca',
6+
lang: 'en',
7+
};

0 commit comments

Comments
 (0)