From 94ce0031d7ff4523dccf9267da8558ab6452c3dd Mon Sep 17 00:00:00 2001 From: mocusez Date: Tue, 25 Feb 2025 02:10:57 +1100 Subject: [PATCH] feat(route): add Andy Pavlo Blog (#18447) --- lib/routes/cmu/andypavlo/blog.ts | 55 ++++++++++++++++++++++++++++++++ lib/routes/cmu/namespace.ts | 7 ++++ 2 files changed, 62 insertions(+) create mode 100644 lib/routes/cmu/andypavlo/blog.ts create mode 100644 lib/routes/cmu/namespace.ts diff --git a/lib/routes/cmu/andypavlo/blog.ts b/lib/routes/cmu/andypavlo/blog.ts new file mode 100644 index 00000000000000..c31ed07b2a61c6 --- /dev/null +++ b/lib/routes/cmu/andypavlo/blog.ts @@ -0,0 +1,55 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +async function getArticles() { + const url = 'https://www.cs.cmu.edu/~pavlo/blog/index.html'; + const { data: res } = await got(url); + const $ = load(res); + + const list = $('.row.mb-3') + .toArray() + .map((element) => { + const $item = $(element); + const $title = $item.find('h4 a'); + const $date = $item.find('.text-muted'); + const $description = $item.find('p'); + + return { + title: $title.text().trim(), + link: $title.attr('href'), + description: $description.text().trim(), + pubDate: parseDate($date.attr('title')), + guid: $title.attr('href'), + }; + }); + return list; +} + +export const route: Route = { + path: '/andypavlo/blog', + categories: ['blog'], + example: '/cmu/andypavlo/blog', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: 'Andy Pavlo Blog', + maintainers: ['mocusez'], + handler, +}; + +async function handler() { + const articles = await getArticles(); + return { + title: 'Andy Pavlo - Carnegie Mellon University', + link: 'https://www.cs.cmu.edu/~pavlo/blog/index.html', + item: articles, + }; +} diff --git a/lib/routes/cmu/namespace.ts b/lib/routes/cmu/namespace.ts new file mode 100644 index 00000000000000..5bb54310581c72 --- /dev/null +++ b/lib/routes/cmu/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Carnegie Mellon University', + url: 'www.cmu.edu', + lang: 'en', +};