Skip to content

Commit

Permalink
fix(route): oup (#17309)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Oct 25, 2024
1 parent c975644 commit b76ffa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
39 changes: 20 additions & 19 deletions lib/routes/oup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import path from 'node:path';
Expand All @@ -29,46 +29,47 @@ export const route: Route = {
source: ['academic.oup.com/', 'academic.oup.com/:name/issue'],
},
],
name: 'Oxford Academic',
maintainers: [],
name: 'Oxford Academic - Journal',
maintainers: ['Fatpandac'],
handler,
url: 'academic.oup.com/',
description: `#### Journal {#oxford-university-press-oxford-academic-journal}`,
};

async function handler(ctx) {
const name = ctx.req.param('name');
const url = `${rootUrl}/${name}/issue`;

const response = await got(url);
const cookies = response.headers['set-cookie'].map((item) => item.split(';')[0]).join(';');
const $ = load(response.data);
const response = await ofetch.raw(url);
const cookies = response.headers
.getSetCookie()
.map((item) => item.split(';')[0])
.join(';');
const $ = load(response._data);
const list = $('div.al-article-items')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('a.at-articleLink').text(),
link: new URL($(item).find('a.at-articleLink').attr('href'), rootUrl).href,
}))
.get();
}));

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link, {
const detailResponse = await ofetch(item.link, {
headers: {
Cookie: cookies,
},
});
const content = load(detailResponse.data);
const $ = load(detailResponse);

item.author = content('a.linked-name.js-linked-name-trigger').text();
item.author = $('.al-authors-list button').text();
item.description = art(path.join(__dirname, 'templates/article.art'), {
abstractContent: content('section.abstract > p.chapter-para').text(),
keywords: content('div.kwd-group > a')
.map((_, item) => $(item).text())
.get()
.join(','),
abstractContent: $('section.abstract > p.chapter-para').text(),
});
item.pubDate = parseDate(content('div.citation-date').text());
item.pubDate = parseDate($('div.citation-date').text());
item.category = $('div.kwd-group > a')
.toArray()
.map((item) => $(item).text());

return item;
})
Expand Down
4 changes: 0 additions & 4 deletions lib/routes/oup/templates/article.art
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<h2>Abstract</h2>
<p>{{abstractContent}}</p>
{{ if keywords }}
<h2>Keywords</h2>
<p>{{keywords}}</p>
{{ /if }}

0 comments on commit b76ffa1

Please sign in to comment.