rsshub
Version:
Make RSS Great Again!
69 lines (68 loc) • 2.31 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/mit/oge.ts
const route = {
path: "/oge/:type?/:name?",
categories: ["university"],
example: "/mit/oge/department/electrical-engineering-and-computer-science",
parameters: {
type: {
description: "Filter type",
options: [{
value: "category",
label: "Blog category"
}, {
value: "department",
label: "Department"
}]
},
name: "Filter value, can be found in the filter URL of the blog page, e.g. `electrical-engineering-and-computer-science` in `https://oge.mit.edu/news-and-events/blog/?_sft_department=electrical-engineering-and-computer-science`"
},
radar: [{
source: ["oge.mit.edu/news-and-events/blog"],
target: "/oge"
}],
name: "Office of Graduate Education Blog",
maintainers: ["LogicJake"],
handler,
url: "oge.mit.edu/news-and-events/blog"
};
const host = "https://oge.mit.edu";
async function handler(ctx) {
const { type, name } = ctx.req.param();
const filter = type === "category" ? "_sft_blog_category" : type === "department" ? "_sft_department" : void 0;
const link = filter && name ? `${host}/news-and-events/blog/?${filter}=${name}` : `${host}/news-and-events/blog/`;
const $ = load((await rofetch(`${host}/`, { query: {
sfid: "112",
sf_action: "get_data",
sf_data: "results",
lang: "en",
...filter && name && { [filter]: name }
} })).results);
const list = $(".search-filter-result").toArray().map((elem) => {
const $elem = $(elem);
const a = $elem.find("h3 a");
const [date, author] = $elem.find("p.meta-date").text().split("|", 2);
return {
title: a.text(),
link: a.attr("href"),
pubDate: parseDate(date),
author: author?.trim()
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const description = load(await rofetch(item.link))(".blog-main .col-12").first();
description.find("h2, p.meta-date").remove();
item.description = description.html() ?? void 0;
return item;
})));
return {
title: `MIT Office of Graduate Education Blog${name ? ` - ${name}` : ""}`,
link,
item: items
};
}
//#endregion
export { route };