diff --git a/components/expand-data.js b/components/expand-data.js index 12dfde1..8cd2e09 100644 --- a/components/expand-data.js +++ b/components/expand-data.js @@ -13,10 +13,11 @@ export default function(dom, data) { // Dates // TODO: fix updated date - if (data.published) { - data.publishedDate = new Date(data.published); - data.updatedDate = new Date(data.published || data.updated); - + if (data.published){//} && data.journal) { + data.volume = data.published.getFullYear() - 2015; + data.issue = data.published.getMonth() + 1; + } + /* //let RFC = d3.timeFormat("%a, %d %b %Y %H:%M:%S %Z"); let months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]; let zeroPad = (n) => { return n < 10 ? "0" + n : n; }; @@ -28,7 +29,7 @@ export default function(dom, data) { data.publishedDayPadded = zeroPad(data.publishedDate.getDate()); data.volume = data.publishedDate.getFullYear() - 2015; data.issue = data.publishedDate.getMonth() + 1; - } + }*/ diff --git a/components/front-matter.js b/components/front-matter.js index 474a6a9..941b596 100644 --- a/components/front-matter.js +++ b/components/front-matter.js @@ -10,6 +10,9 @@ export default function(dom, data) { data.title = localData.title; data.description = localData.description; + data.published = new Date(localData.published); + data.updated = new Date(localData.published || localData.updated); + data.authors = localData.authors.map((author, i) =>{ let a = {}; let name = Object.keys(author)[0]; @@ -24,6 +27,7 @@ export default function(dom, data) { } return a; }); + } } diff --git a/components/meta.js b/components/meta.js index 891c17b..fa18230 100644 --- a/components/meta.js +++ b/components/meta.js @@ -1,7 +1,13 @@ export default function(dom, data) { let head = dom.querySelector("head"); + let appendHead = html => appendHtml(head, html); - appendHtml(head, ` + function meta(name, content) { + if (content) + appendHead(``); + } + + appendHead(` @@ -9,17 +15,17 @@ export default function(dom, data) { ${data.title} `); - appendHtml(head, ` + appendHead(` - - + + `); data.authors.forEach((a) => { appendHtml(head, ` `) }); - appendHtml(head, ` + appendHead(` @@ -30,7 +36,7 @@ export default function(dom, data) { `); - appendHtml(head, ` + appendHead(` @@ -41,39 +47,37 @@ export default function(dom, data) { `); - appendHtml(head, ` + appendHead(` - - - - - - - `); - if (data.journal) { - appendHtml(head, ` - - - - - `); - } + + let journal = data.journal || {}; + let zeroPad = (n) => { return n < 10 ? "0" + n : n; }; + let publishedYear = data.published.getFullYear(); + let publishedMonthPadded = zeroPad(data.published.getMonth() + 1); + let publishedDayPadded = zeroPad(data.published.getDate()); + meta("citation_title", data.title); + meta("citation_publication_date", data.published? `${publishedYear}/${publishedMonthPadded}/${publishedDayPadded}` : undefined); + meta("citation_fulltext_html_url", data.url); + meta("citation_volume", data.volume); + meta("citation_issue", data.issue); + meta("citation_firstpage", data.doiSuffix? `e${data.doiSuffix}` : undefined); + meta("citation_doi", data.doi); + meta("citation_journal_title", journal.name); + meta("citation_journal_abbrev", journal.nameAbbrev); + meta("citation_issn", journal.issn); + meta("citation_publisher", journal.publisher); + (data.authors || []).forEach((a) => { - appendHtml(head, ` - - - `) + meta("citation_author", `${a.lastName}, ${a.firstName}`); + meta("citation_author_institution", a.affiliation); }); if (data.citations) { let citationKeys = Object.keys(data.citations); - citationKeys.forEach(key => { - console.log(key); - appendHtml(head, ` - - `); - }); + citationKeys.forEach(key => + meta("citation_reference", citation_meta_content(data.citations[key]) ) + ); } } diff --git a/examples/article.html b/examples/article.html index ec0fc45..cf2f1f9 100644 --- a/examples/article.html +++ b/examples/article.html @@ -5,6 +5,7 @@