|
| 1 | +import { load } from 'cheerio'; |
| 2 | +import sanitizeHtml from 'sanitize-html'; |
| 3 | + |
| 4 | +import type { Route } from '@/types'; |
| 5 | +import ofetch from '@/utils/ofetch'; |
| 6 | +import { parseDate } from '@/utils/parse-date'; |
| 7 | + |
| 8 | +export const route: Route = { |
| 9 | + path: '/release-note', |
| 10 | + categories: ['program-update'], |
| 11 | + example: '/gitkraken/release-note', |
| 12 | + features: { |
| 13 | + requireConfig: false, |
| 14 | + requirePuppeteer: false, |
| 15 | + antiCrawler: false, |
| 16 | + supportBT: false, |
| 17 | + supportPodcast: false, |
| 18 | + supportScihub: false, |
| 19 | + }, |
| 20 | + radar: [ |
| 21 | + { |
| 22 | + source: ['help.gitkraken.com/gitkraken-desktop/current/'], |
| 23 | + }, |
| 24 | + { |
| 25 | + source: ['www.gitkraken.com/'], |
| 26 | + }, |
| 27 | + ], |
| 28 | + name: 'Release Notes', |
| 29 | + maintainers: ['TonyRL'], |
| 30 | + url: 'help.gitkraken.com/gitkraken-desktop/current/', |
| 31 | + handler, |
| 32 | +}; |
| 33 | + |
| 34 | +async function handler() { |
| 35 | + const baseUrl = 'https://help.gitkraken.com'; |
| 36 | + const link = `${baseUrl}/gitkraken-desktop/current/`; |
| 37 | + const response = await ofetch(`${baseUrl}/wp-json/wp/v2/posts/1964`); |
| 38 | + |
| 39 | + const $ = load(response.content.rendered, null, false); |
| 40 | + |
| 41 | + const items = $('h2') |
| 42 | + .toArray() |
| 43 | + .map((item) => { |
| 44 | + const $item = $(item); |
| 45 | + |
| 46 | + return { |
| 47 | + title: $item.text(), |
| 48 | + description: $item |
| 49 | + .next() |
| 50 | + .nextUntil('hr') |
| 51 | + .toArray() |
| 52 | + .map((el) => $.html(el)) |
| 53 | + .join(''), |
| 54 | + link: `${link}#${$item.prev().find('a[id]').attr('id')}`, |
| 55 | + pubDate: parseDate($item.next().find('kbd').text()?.split('day, ')[1].trim(), 'MMMM Do, YYYY', 'en'), |
| 56 | + }; |
| 57 | + }); |
| 58 | + |
| 59 | + return { |
| 60 | + title: response.title.rendered, |
| 61 | + description: sanitizeHtml(response.excerpt.rendered, { allowedTags: [], allowedAttributes: {} }), |
| 62 | + link, |
| 63 | + item: items, |
| 64 | + }; |
| 65 | +} |
0 commit comments