diff --git a/lib/routes/academia/namespace.ts b/lib/routes/academia/namespace.ts new file mode 100644 index 000000000..40f92fe27 --- /dev/null +++ b/lib/routes/academia/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Academia', + url: 'https://www.academia.edu/', +}; diff --git a/lib/routes/academia/topics.ts b/lib/routes/academia/topics.ts new file mode 100644 index 000000000..477306530 --- /dev/null +++ b/lib/routes/academia/topics.ts @@ -0,0 +1,48 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/topic/:interest', + example: '/academia/topic/Urban_History', + radar: [ + { + source: ['academia.edu/Documents/in/:interest'], + target: '/topic/:interest', + }, + ], + name: 'interest', + maintainers: ['K33k0'], + categories: ['journal'], + handler, + url: 'academia.edu', +}; + +async function handler(ctx) { + const interest = ctx.req.param('interest'); + const response = await ofetch(`https://www.academia.edu/Documents/in/${interest}/MostRecent`); + const $ = load(response); + const list = $('.works > .u-borderBottom1') + .toArray() + .map((item) => { + const tagsElem = $(item).find('li.InlineList-item.u-positionRelative > span > script').text().replaceAll('}{', '},{'); + let categories = []; + if (tagsElem !== null) { + const categoriesJSON = JSON.parse(`[${tagsElem}]`); + categories = categoriesJSON.map((category) => category.name); + } + + return { + title: $(item).find('.header .title').text(), + link: $(item).find('.header .title > a').attr('href'), + author: $(item).find('span[itemprop=author] > a').text(), + description: $(item).find('.complete').text(), + category: categories, + }; + }); + return { + title: `academia.edu | ${interest} documents`, + link: `https://academia.edu/Documents/in/${interest}/MostRecent`, + item: list, + }; +}