1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
export const tacUrlToBibtex = async (url: string) => {
const cheerio = await import("npm:cheerio");
const html = await fetchText(url);
const $ = cheerio.load(html);
const title = $("h1").text().trim().replace(/\s+/g, " ");
const authors = $("h2").text().trim().replace(/\s+/g, " ").split(
/(?:, and | and |, )/,
).map((author) => {
const lastSpaceIndex = author.lastIndexOf(" ");
const fstName = author.slice(0, lastSpaceIndex);
const lstName = author.slice(lastSpaceIndex + 1);
return `${lstName}, ${fstName}`;
}).join(" and ");
const meta =
$("body p:nth-child(6)").text().trim().replace(/\s+/g, " ").match(
/(?<journal>Theory and Applications of Categories), Vol. (?<volume>\d+), (?<year>\d+), No. (?<number>\d+), pp? (?<pages>[0-9-]+)\./,
).groups;
const key = `${authors.split(",")[0]}${meta.year}${title.split(" ")[0]}`
.toLowerCase();
return `@article{${key},
title={${title}},
author={${authors}},
journal={${meta.journal}},
volume={${meta.volume}},
number={${meta.number}},
pages={${meta.pages.replace("-", "--")}},
year={${meta.year}}
}`;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023