From 712d859dad066052c3a81d823830524e106d4850 Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Tue, 10 Jan 2017 12:42:59 -0800 Subject: [PATCH] more work on citations --- components/citation.js | 102 ++++++++++++++++++++---------- components/hover-box.txt | 4 +- components/styles-base.css | 5 ++ examples/article.html | 126 ++++++++++++++++++++++++++++++++++++- 4 files changed, 198 insertions(+), 39 deletions(-) diff --git a/components/citation.js b/components/citation.js index 48f5236..1fdf992 100644 --- a/components/citation.js +++ b/components/citation.js @@ -15,9 +15,10 @@ export default function(dom, data) { var cite_string = inline_cite_short(keys); var cite_hover_str = ""; keys.map((key,n) => { - if (n>0) cite_hover_str += "
"; - cite_hover_str += bibliography_cite(data.bibliography[key], true); + if (n>0) cite_hover_str += "

"; + cite_hover_str += hover_cite(data.bibliography[key]); }); + cite_hover_str = cite_hover_str.replace(/"/g, "'") el.innerHTML = `${cite_string}`; } }); @@ -62,41 +63,52 @@ export default function(dom, data) { return keys.map(cite_string).join(", "); } + function author_string(ent, template, sep, finalSep){ + var names = ent.author.split(" and "); + let name_strings = names.map(name => { + var last = name.split(",")[0].trim(); + var firsts = name.split(",")[1]; + var initials = ""; + if (firsts != undefined) { + initials = firsts.trim().split(" ").map(s => s.trim()[0]); + initials = initials.join(".")+"."; + } + return template.replace("F", firsts) + .replace("L", last) + .replace("I", initials); + }); + if (names.length > 1) { + var str = name_strings.slice(0, names.length-1).join(sep); + str += (finalSep || sep) + name_strings[names.length-1]; + return str; + } else { + return name_strings[0]; + } + } + + function venue_string(ent) { + var cite = (ent.journal || ent.booktitle || "") + if ("volume" in ent){ + var issue = ent.issue || ent.number; + issue = (issue != undefined)? "("+issue+")" : ""; + cite += ", Vol " + ent.volume + issue; + } + if ("pages" in ent){ + cite += ", pp. " + ent.pages + } + cite += ". " + if ("publisher" in ent){ + cite += ent.publisher + "."; + } + return cite; + } + function bibliography_cite(ent, fancy){ if (ent){ - var names = ent.author.split(" and "); - var cite = ""; - let name_strings = names.map(name => { - var last = name.split(",")[0].trim(); - var firsts = name.split(",")[1]; - if (firsts != undefined) { - var initials = firsts.trim().split(" ").map(s => s.trim()[0]); - return last + ", " + initials.join(".")+"."; - } - return last; - }); - if (names.length > 1) { - cite += name_strings.slice(0, names.length-1).join(", "); - cite += " and " + name_strings[names.length-1]; - } else { - cite += name_strings[0] - } + var cite = author_string(ent, "L, I", ", ", " and "); cite += ", " + ent.year + ". " - if (fancy){ - cite += "" + ent.title + ". " - } else { - cite += ent.title + ". " - } - cite += (ent.journal || ent.booktitle || "") - if ("volume" in ent){ - var issue = ent.issue || ent.number; - issue = (issue != undefined)? "("+issue+")" : ""; - cite += ", Vol " + ent.volume + issue; - } - if ("pages" in ent){ - cite += ", pp. " + ent.pages - } - cite += ". " + cite += ent.title + ". "; + cite += venue_string(ent); if (fancy && ent.url && ent.url.slice(-4) == ".pdf") { cite = `${cite} [pdf]` } @@ -106,6 +118,28 @@ export default function(dom, data) { } } + function hover_cite(ent){ + if (ent){ + var cite = ""; + cite += "" + ent.title + ""; + if (ent.url && ent.url.slice(-4) == ".pdf") { + cite = `${cite}  [PDF]` + } + if (ent.url && ent.url.slice(-5) == ".html") { + cite = `${cite}  [HTML]` + } + cite += "
" + cite += author_string(ent, "I L", ", ") + ".
"; + cite += venue_string(ent).trim() + " " + ent.year + ". " + if ("doi" in ent) { + cite += `
DOI: ${ent.doi}` + } + return cite + } else { + return "?"; + } + } + //https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah function get_URL(ent){ diff --git a/components/hover-box.txt b/components/hover-box.txt index 001be09..94ac8e1 100644 --- a/components/hover-box.txt +++ b/components/hover-box.txt @@ -32,8 +32,8 @@ function DistillHoverBox(key, pos){ top: ${top}px; left: ${left}px; padding: ${padding}px; - border-radius: ${pretty? 6 : 0}px; - box-shadow: 0px 0px 18px 6px #777;" > + border-radius: ${pretty? 3 : 0}px; + box-shadow: 0px 0px 18px 3px #777;" > ${DistillHoverBox.contentMap[key]} `; diff --git a/components/styles-base.css b/components/styles-base.css index bb154e2..ca62d77 100644 --- a/components/styles-base.css +++ b/components/styles-base.css @@ -11,6 +11,11 @@ body { margin: 0; } +dt-article .citation { + color: #668; + cursor: pointer; +} + /* html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, diff --git a/examples/article.html b/examples/article.html index c51e8ec..ddfdae1 100644 --- a/examples/article.html +++ b/examples/article.html @@ -18,16 +18,136 @@

A description of the article

This is the first paragraph of the article.

-

We can also cite external publications.

+

We can also cite external publications.

Contributions