feat(route): adds academia.edu route #12849 (#15699)

* feat: adds academia.edu route #12849

* fixes unused variable

* Fixes further formatting issues

* Updates namespace name

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* updates namespace to meet stndards

updates namespace to meet stndards

* updates route name to protect further development

* adds example

* Updates where data is pulled from, adding some extras

* fix: add categories

---------
This commit is contained in:
Kieran Wynne
2024-06-02 14:38:21 +08:00
committed by GitHub
co-authored by Tony
parent ec4a03e221
commit c846973dd2
2 changed files with 54 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Academia',
url: 'https://www.academia.edu/',
};
+48
View File
@@ -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,
};
}