fix bibliography citation issues

This commit is contained in:
Christopher Olah
2017-01-13 12:44:47 -08:00
parent f6c8a2a870
commit 8627c53506
2 changed files with 23 additions and 10 deletions
+2
View File
@@ -15,6 +15,8 @@ export default function(dom, data) {
val = val.replace(/[\t\n ]+/g, " ");
val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
(full, x, char) => char);
val = val.replace(/{\\([a-zA-Z])}/g,
(full, char) => char);
e.entryTags[k] = val;
}
bibliography[e.citationKey] = e.entryTags;
+21 -10
View File
@@ -68,16 +68,22 @@ export default function(dom, data) {
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];
name = name.trim();
if (name.indexOf(",") != -1){
var last = name.split(",")[0].trim();
var firsts = name.split(",")[1];
} else {
var last = name.split(" ").slice(-1)[0].trim();
var firsts = name.split(" ").slice(0,-1).join(" ");
}
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);
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);
@@ -98,9 +104,10 @@ export default function(dom, data) {
if ("pages" in ent){
cite += ", pp. " + ent.pages
}
cite += ". "
if (cite != "") cite += ". "
if ("publisher" in ent){
cite += ent.publisher + ".";
cite += ent.publisher;
if (cite[cite.length-1] != ".") cite += ".";
}
return cite;
}
@@ -129,8 +136,12 @@ export default function(dom, data) {
function bibliography_cite(ent, fancy){
if (ent){
var cite = author_string(ent, "L, I", ", ", " and ");
cite += ", " + ent.year + ". "
var cite = author_string(ent, "${L}, ${I}", ", ", " and ");
if (ent.year || ent.date){
cite += ", " + (ent.year || ent.date) + ". "
} else {
cite += ". "
}
cite += "<b>" + ent.title + "</b>. ";
cite += venue_string(ent);
cite += doi_string(ent);
@@ -147,7 +158,7 @@ export default function(dom, data) {
cite += "<b>" + ent.title + "</b>";
cite += link_string(ent);
cite += "<br>"
cite += author_string(ent, "I L", ", ") + ".<br>";
cite += author_string(ent, "${I} ${L}", ", ") + ".<br>";
cite += venue_string(ent).trim() + " " + ent.year + ". "
cite += doi_string(ent, true);
return cite