Files
RSSHub/lib/routes/brave/latest.ts
T
Tony d585a87daf fix: allow multiple radar rules per route (#14800)
* fix: allow multiple radar rules per route

* fix: github folder

* feat: add namespace to radar target

* docs: fix types url
2024-03-16 03:28:44 +08:00

66 lines
1.7 KiB
TypeScript

import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/latest',
categories: ['program-update'],
example: '/brave/latest',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['brave.com/latest', 'brave.com/'],
},
],
name: 'Release Notes',
maintainers: ['nczitzk'],
handler,
url: 'brave.com/latest',
};
async function handler() {
const rootUrl = 'https://brave.com';
const currentUrl = `${rootUrl}/latest`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
const items = $('.box h3')
.toArray()
.map((item) => {
item = $(item);
const title = item.text();
const device = item.parent().find('h2').text();
const matchVersion = title.match(/(v[\d.]+)/);
const matchDate = title.match(/\((.*?)\)/);
return {
title: `[${device}] ${title}`,
link: currentUrl,
guid: `${currentUrl}#${device}-${matchVersion?.[1] ?? title}`,
description: item.next().html(),
pubDate: parseDate(matchDate?.[1].replace(/(st|nd|rd|th)?,/, ''), ['MMMM D YYYY', 'MMM D YYYY']),
};
});
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}