From 5e5f5f8b8ba73fd8d3182b9b3b7ff338cd6cc3e0 Mon Sep 17 00:00:00 2001 From: Christopher Olah Date: Wed, 4 Jan 2017 13:55:39 -0800 Subject: [PATCH] work on meta tags --- components/meta.js | 105 +++++++++++++++++++++++++++++++++++++++++++++ index.js | 11 +++-- test-data.js | 46 ++++++++++++++++++++ 3 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 components/meta.js create mode 100644 test-data.js diff --git a/components/meta.js b/components/meta.js new file mode 100644 index 0000000..aeec664 --- /dev/null +++ b/components/meta.js @@ -0,0 +1,105 @@ +export default function(dom, data) { + dom.querySelector("html").setAttribute("lang", "en") + let head = dom.querySelector("head"); + + if (!dom.querySelector("meta[charset]")) { + appendHtml(head, ``); + } + if (!dom.querySelector("meta[name=viewport]")) { + appendHtml(head, ``); + } + + appendHtml(head, ` + + + + + ${data.title} + `); + + appendHtml(head, ` + + + + `); + data.authors.forEach((a) => { + appendHtml(head, ` + `) + }); + + appendHtml(head, ` + + + + + + + + + `); + + appendHtml(head, ` + + + + + + + + + `); + + appendHtml(head, ` + + + + + + + + + + + + + `); + data.authors.forEach((a) => { + appendHtml(head, ` + + + `) + }); + + Object.keys(data.citations).forEach(key => { + console.log(key); + appendHtml(head, ` + + `); + }); +} + + + + +function appendHtml(el, html) { + el.innerHTML += html; +} + +function citation_meta_content(ref){ + var content = `citation_title=${ref.title};`; + ref.author.split(" and ").forEach(author => { + content += `citation_author=${author.trim()};`; + }); + if ("journal" in ref){ + content += `citation_journal_title=${ref.journal};`; + } + if ("volume" in ref) { + content += `citation_volume=${ref.volume};`; + } + if ("issue" in ref || "number" in ref){ + content += `citation_number=${ref.issue || ref.number};`; + } + /*content += `citation_first_page=${};`; + content += `citation_publication_date=${};`;*/ + return content; +} diff --git a/index.js b/index.js index 2d576f1..d7de79b 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ import citeData from "./components/cite-data"; +import meta from "./components/meta"; import styles from "./components/styles"; import header from "./components/header"; import appendix from "./components/appendix"; @@ -6,24 +7,28 @@ import footer from "./components/footer"; import citation from "./components/citation"; import markdown from "./components/markdown"; import code from "./components/code"; - +import testData from "./test-data"; function render(dom, data) { styles(dom, data); document.addEventListener("DOMContentLoaded", function(event) { - citeData(dom, data) + citeData(dom, data); + meta(dom, data); header(dom, data); appendix(dom, data); footer(dom, data); markdown(dom, data); code(dom, data); citation(dom, data); + console.log("final data:") + for (var k in data) {console.log(" ", k, ": ", data[k])} }); } + if(window.document) { - render(window.document, []); + render(window.document, testData); } export default render; diff --git a/test-data.js b/test-data.js new file mode 100644 index 0000000..027f553 --- /dev/null +++ b/test-data.js @@ -0,0 +1,46 @@ +export default { + "title": "Experiments in Handwriting with a Neural Network", + "description": "Several interactive visualizations of a generative model of handwriting. Some are fun, some are serious.", + "url": "http://distill.pub/2016/handwriting/", + "github": "https://github.com/distillpub/post--handwriting", + "firstPublished": "Tue Dec 6 2016 21:39:33 GMT-0700 (PDT)", + "lastPublished": "Tue Dec 6 2016 21:39:33 GMT-0700 (PDT)", + "authors": [ + { + "firstName": "Shan", + "lastName": "Carter", + "personalURL": "http://shancarter.com", + "affiliation": "Google Brain", + "affiliationURL": "http://g.co/brain" + }, + { + "firstName": "David", + "lastName": "Ha", + "personalURL": "https://github.com/hardmaru", + "affiliation": "Google Brain", + "affiliationURL": "http://g.co/brain" + }, + { + "firstName": "Ian", + "lastName": "Johnson", + "personalURL": "https://github.com/enjalot", + "affiliation": "Google Cloud", + "affiliationURL": "" + }, + { + "firstName": "Chris", + "lastName": "Olah", + "personalURL": "http://colah.github.io/", + "affiliation": "Google Brain", + "affiliationURL": "http://g.co/brain" + } + ], + journal: { + "title": "Distill", + "full_title": "Distill", + "abbrev_title": "Distill", + "url": "http://distill.pub", + "doi": "00.0000/dstl", + "issn": "0000-0000" + } + };