diff --git a/components/bibliography.js b/components/bibliography.js index 8eb9b61..8e49693 100644 --- a/components/bibliography.js +++ b/components/bibliography.js @@ -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; diff --git a/components/citation.js b/components/citation.js index b80fb73..0873ce0 100644 --- a/components/citation.js +++ b/components/citation.js @@ -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 += "" + ent.title + ". "; cite += venue_string(ent); cite += doi_string(ent); @@ -147,7 +158,7 @@ export default function(dom, data) { cite += "" + ent.title + ""; cite += link_string(ent); cite += "
" - cite += author_string(ent, "I L", ", ") + ".
"; + cite += author_string(ent, "${I} ${L}", ", ") + ".
"; cite += venue_string(ent).trim() + " " + ent.year + ". " cite += doi_string(ent, true); return cite