From 07dee84d2b01bad59ffa813a40d29aa7a4b67a48 Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Sat, 7 Jan 2017 12:45:43 -0800 Subject: [PATCH 1/7] add expand data --- components/expand-data.js | 33 +++++++++++++++++++++++++++++++++ index.js | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 components/expand-data.js diff --git a/components/expand-data.js b/components/expand-data.js new file mode 100644 index 0000000..9f3aa46 --- /dev/null +++ b/components/expand-data.js @@ -0,0 +1,33 @@ +export default function(dom, data) { + + // paths + //data.distillPath = post.distillPath; + //data.githubPath = post.githubPath; + //data.url = "http://distill.pub/" + post.distillPath; + //data.githubUrl = "https://github.com/" + post.githubPath; + + // Homepage + //data.homepage = !post.noHomepage; + + // Dates + // TODO: fix updated date + if (data.published) { + data.publishedDate = new Date(data.published); + data.updatedDate = new Date(data.published || data.updated); + + //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; }; + //data.publishedDateRFC = RFC(data.publishedDate); + data.publishedYear = data.publishedDate.getFullYear(); + data.publishedMonth = months[data.publishedDate.getMonth()]; + data.publishedDay = data.publishedDate.getDate(); + data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1); + data.publishedDayPadded = zeroPad(data.publishedDate.getDate()); + data.volume = data.publishedDate.getFullYear() - 2015; + data.issue = data.publishedDate.getMonth() + 1; + } + + + +} diff --git a/index.js b/index.js index 07b98d0..d9c9459 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ import html from "./components/html"; import styles from "./components/styles"; import frontMatter from "./components/front-matter"; import bibliography from "./components/bibliography"; +import expandData from "./components/expand-data"; import meta from "./components/meta"; import header from "./components/header"; import appendix from "./components/appendix"; @@ -18,6 +19,7 @@ function render(dom, data) { document.addEventListener("DOMContentLoaded", function(event) { frontMatter(dom, data); bibliography(dom, data); + expandData(dom, data); meta(dom, data); header(dom, data); appendix(dom, data); From 65892fd75d3d75a40bd4a9ee56be45890c0963ad Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Sun, 8 Jan 2017 10:16:31 -0800 Subject: [PATCH 2/7] add data expansion --- components/expand-data.js | 2 ++ components/meta.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/expand-data.js b/components/expand-data.js index 9f3aa46..12dfde1 100644 --- a/components/expand-data.js +++ b/components/expand-data.js @@ -1,5 +1,7 @@ export default function(dom, data) { + data.authors = data.authors || []; + // paths //data.distillPath = post.distillPath; //data.githubPath = post.githubPath; diff --git a/components/meta.js b/components/meta.js index 8ce9753..891c17b 100644 --- a/components/meta.js +++ b/components/meta.js @@ -48,14 +48,18 @@ export default function(dom, data) { - - - - `); - data.authors.forEach((a) => { + if (data.journal) { + appendHtml(head, ` + + + + + `); + } + (data.authors || []).forEach((a) => { appendHtml(head, ` From b7c7417a57d72a3cba2d026526a2830f7deed17f Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Sun, 8 Jan 2017 11:51:03 -0800 Subject: [PATCH 3/7] refactor data object --- components/expand-data.js | 11 +++--- components/front-matter.js | 4 +++ components/meta.js | 68 ++++++++++++++++++++------------------ examples/article.html | 1 + examples/tutorial.html | 1 + index.js | 3 +- 6 files changed, 50 insertions(+), 38 deletions(-) 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 @@