From 372904d363ee559b51c6cc0ffad5a07591b9b0bb Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:39:41 +0800 Subject: [PATCH] feat(route): add cursor changelog (#17978) --- lib/routes/cursor/changelog.ts | 63 ++++++++++++++++++++++++++++++++++ lib/routes/cursor/namespace.ts | 8 +++++ 2 files changed, 71 insertions(+) create mode 100644 lib/routes/cursor/changelog.ts create mode 100644 lib/routes/cursor/namespace.ts diff --git a/lib/routes/cursor/changelog.ts b/lib/routes/cursor/changelog.ts new file mode 100644 index 00000000000000..3a81f19315d665 --- /dev/null +++ b/lib/routes/cursor/changelog.ts @@ -0,0 +1,63 @@ +import { Route } from '@/types'; + +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/changelog', + categories: ['program-update'], + example: '/cursor/changelog', + url: 'www.cursor.com/changelog', + name: 'Changelog', + maintainers: ['p3psi-boo'], + radar: [ + { + source: ['www.cursor.com/changelog'], + target: '/cursor/changelog', + }, + ], + handler, +}; + +async function handler() { + const url = 'https://www.cursor.com/changelog'; + + const response = await got({ + method: 'get', + url, + }); + + const $ = load(response.data); + + const alist = $('article'); + + const list = alist.toArray().map((item) => { + const leftSide = item.firstChild! as unknown as Element; + const version = $(leftSide.firstChild!).text(); + const dateLabel = $(leftSide.lastChild!).text(); + const date = parseDate(dateLabel); + + // 从第二个子元素开始到结束都是内容 + const content = item.children + .slice(1) + .map((child) => $(child).html()) + .join(''); + const titleElement = $('h2 a', item); + const link = titleElement.attr('href'); + const title = titleElement.text(); + + return { + title: `${version} - ${title}`, + description: content, + link: `https://www.cursor.com${link}`, + pubDate: date, + }; + }); + + return { + title: 'Cursor Changelog', + link: 'https://www.cursor.com/changelog', + item: list, + }; +} diff --git a/lib/routes/cursor/namespace.ts b/lib/routes/cursor/namespace.ts new file mode 100644 index 00000000000000..a8b7b6abdcda4c --- /dev/null +++ b/lib/routes/cursor/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Cursor', + url: 'www.cursor.com', + description: '', + lang: 'en', +};