Compare commits

...
6 Commits
Author SHA1 Message Date
Shan Carter 758697ab97 0.0.16 2017-01-09 18:22:44 -08:00
Shan Carter 4428ad1a5f Cleanup 2017-01-09 18:22:39 -08:00
Shan Carter c77fbbd18f 0.0.15 2017-01-09 18:11:32 -08:00
Shan Carter adcfba4627 Updating data processing 2017-01-09 18:09:59 -08:00
Shan Carter 6ef3847bf6 0.0.14 2017-01-09 17:37:13 -08:00
Shan Carter 0b68c4ea1f fix 2017-01-09 17:37:12 -08:00
12 changed files with 101 additions and 79 deletions
-2
View File
@@ -8,12 +8,10 @@ export default function(dom, data) {
}*/ }*/
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite")); var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
console.log(citeTags);
citeTags.forEach(el => { citeTags.forEach(el => {
var key = el.getAttribute("key"); var key = el.getAttribute("key");
if (key) { if (key) {
var keys = key.split(","); var keys = key.split(",");
console.log(keys)
var cite_string = inline_cite_short(keys); var cite_string = inline_cite_short(keys);
el.innerHTML = cite_string; el.innerHTML = cite_string;
} }
+8 -1
View File
@@ -39,5 +39,12 @@ dt-footer .logo {
export default function(dom, data) { export default function(dom, data) {
let el = dom.querySelector("dt-footer"); let el = dom.querySelector("dt-footer");
if(el) el.innerHTML = html; if(el) {
el.innerHTML = html;
} else {
let footer = dom.createElement("dt-footer");
footer.innerHTML = html;
let b = dom.querySelector("body");
b.appendChild(footer);
}
} }
+25 -24
View File
@@ -1,33 +1,34 @@
import ymlParse from "js-yaml"; import ymlParse from "js-yaml";
export default function(dom, data) { export default function(dom, data) {
let localData = {};
let el = dom.querySelector('script[type="text/front-matter"]'); let el = dom.querySelector('script[type="text/front-matter"]');
//TODO If we don't have a local element, make a request for the document.
if (el) { if (el) {
let text = el.textContent; let text = el.textContent;
let localData = ymlParse.safeLoad(text); localData = ymlParse.safeLoad(text);
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];
let names = name.split(" ");
a.firstName = names.slice(0, names.length - 1).join(" ");
a.lastName = names[names.length -1];
a.personalURL = author[name];
if(localData.affiliations[i]) {
let affiliation = Object.keys(localData.affiliations[i])[0];
a.affiliation = affiliation;
a.affiliationURL = localData.affiliations[i][affiliation];
}
return a;
});
} }
data.title = localData.title ? localData.title : "Untitled";
data.description = localData.description ? localData.description : "No description.";
data.published = localData.published ? new Date(localData.published) : new Date("Invalid");
data.updated = localData.updated ? new Date(localData.updated) : new Date("Invalid");
data.authors = localData.authors ? localData.authors : [];
data.authors = data.authors.map((author, i) =>{
let a = {};
let name = Object.keys(author)[0];
let names = name.split(" ");
a.name = name;
a.firstName = names.slice(0, names.length - 1).join(" ");
a.lastName = names[names.length -1];
a.personalURL = author[name];
if(localData.affiliations[i]) {
let affiliation = Object.keys(localData.affiliations[i])[0];
a.affiliation = affiliation;
a.affiliationURL = localData.affiliations[i][affiliation];
}
return a;
});
} }
+4 -3
View File
@@ -3,13 +3,14 @@
export default function(data) { export default function(data) {
if (data.published == undefined) { if (data.published == undefined) {
console.warn("Can't generate XML for post ", data.title, "with data", data); //console.warn("Can't generate XML for post ", data.title, "with data", data);
return ""; //return "";
data.published = new Date("invalid");
} }
var date = data.published; var date = data.published;
var batch_timestamp = Math.floor(Date.now() / 1000); var batch_timestamp = Math.floor(Date.now() / 1000);
var batch_id = data.authors[0].lastName.split(" ")[0].toLowerCase().slice(0,20); var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
batch_id += "_" + date.getFullYear(); batch_id += "_" + date.getFullYear();
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp; batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
// generate XML // generate XML
+9 -1
View File
@@ -58,5 +58,13 @@ dt-header .nav a {
` `
export default function(dom, data) { export default function(dom, data) {
dom.querySelector('dt-header').innerHTML = html; let el = dom.querySelector("dt-header");
if(el) {
el.innerHTML = html;
} else {
let header = dom.createElement("dt-header");
header.innerHTML = html;
let b = dom.querySelector("body");
b.insertBefore(header, b.firstChild);
}
} }
-1
View File
@@ -5,7 +5,6 @@ export default function(dom) {
let head = dom.querySelector("head"); let head = dom.querySelector("head");
if (!dom.querySelector("meta[charset]")) { if (!dom.querySelector("meta[charset]")) {
let meta = dom.createElement("meta"); let meta = dom.createElement("meta");
meta.setAttribute("charset", "utf-8"); meta.setAttribute("charset", "utf-8");
+49 -35
View File
@@ -11,7 +11,6 @@ var html = function(dom) {
var head = dom.querySelector("head"); var head = dom.querySelector("head");
if (!dom.querySelector("meta[charset]")) { if (!dom.querySelector("meta[charset]")) {
var meta = dom.createElement("meta"); var meta = dom.createElement("meta");
meta.setAttribute("charset", "utf-8"); meta.setAttribute("charset", "utf-8");
@@ -3812,35 +3811,36 @@ var yaml = jsYaml;
var index = yaml; var index = yaml;
var frontMatter = function(dom, data) { var frontMatter = function(dom, data) {
var localData = {};
var el = dom.querySelector('script[type="text/front-matter"]'); var el = dom.querySelector('script[type="text/front-matter"]');
//TODO If we don't have a local element, make a request for the document.
if (el) { if (el) {
var text = el.textContent; var text = el.textContent;
var localData = index.safeLoad(text); localData = index.safeLoad(text);
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(function (author, i) {
var a = {};
var name = Object.keys(author)[0];
var names = name.split(" ");
a.firstName = names.slice(0, names.length - 1).join(" ");
a.lastName = names[names.length -1];
a.personalURL = author[name];
if(localData.affiliations[i]) {
var affiliation = Object.keys(localData.affiliations[i])[0];
a.affiliation = affiliation;
a.affiliationURL = localData.affiliations[i][affiliation];
}
return a;
});
} }
data.title = localData.title ? localData.title : "Untitled";
data.description = localData.description ? localData.description : "No description.";
data.published = localData.published ? new Date(localData.published) : new Date("Invalid");
data.updated = localData.updated ? new Date(localData.updated) : new Date("Invalid");
data.authors = localData.authors ? localData.authors : [];
data.authors = data.authors.map(function (author, i) {
var a = {};
var name = Object.keys(author)[0];
var names = name.split(" ");
a.name = name;
a.firstName = names.slice(0, names.length - 1).join(" ");
a.lastName = names[names.length -1];
a.personalURL = author[name];
if(localData.affiliations[i]) {
var affiliation = Object.keys(localData.affiliations[i])[0];
a.affiliation = affiliation;
a.affiliationURL = localData.affiliations[i][affiliation];
}
return a;
});
}; };
var bibtexParse = createCommonjsModule(function (module, exports) { var bibtexParse = createCommonjsModule(function (module, exports) {
@@ -4350,7 +4350,15 @@ var logo = "<svg viewBox=\"-607 419 64 64\">\n <path style=\"fill: none; stroke
var html$1 = "\n<style>\ndt-header {\n display: block;\n position: relative;\n height: 60px;\n background-color: none;\n width: 100%;\n box-sizing: border-box;\n z-index: 2;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header .content {\n border-bottom: 1px solid rgba(0, 0, 0, 0.3);\n height: 60px;\n}\ndt-header a {\n font-size: 16px;\n height: 60px;\n line-height: 60px;\n text-decoration: none;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header svg {\n width: 24px;\n position: relative;\n top: 4px;\n margin-right: -2px;\n}\ndt-header svg path {\n fill: none;\n stroke: black;\n stroke-width: 1;\n stroke-linejoin: round;\n}\ndt-header .logo {\n font-size: 16px;\n font-weight: 300;\n}\ndt-header .nav {\n float: right;\n}\ndt-header .nav a {\n font-size: 14px;\n}\n</style>\n\n<div class=\"content l-page\">\n <a href=\"/\" class=\"logo\">\n " + logo + "\n Distill\n </a>\n <div class=\"nav\">\n </div>\n</div>\n"; var html$1 = "\n<style>\ndt-header {\n display: block;\n position: relative;\n height: 60px;\n background-color: none;\n width: 100%;\n box-sizing: border-box;\n z-index: 2;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header .content {\n border-bottom: 1px solid rgba(0, 0, 0, 0.3);\n height: 60px;\n}\ndt-header a {\n font-size: 16px;\n height: 60px;\n line-height: 60px;\n text-decoration: none;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header svg {\n width: 24px;\n position: relative;\n top: 4px;\n margin-right: -2px;\n}\ndt-header svg path {\n fill: none;\n stroke: black;\n stroke-width: 1;\n stroke-linejoin: round;\n}\ndt-header .logo {\n font-size: 16px;\n font-weight: 300;\n}\ndt-header .nav {\n float: right;\n}\ndt-header .nav a {\n font-size: 14px;\n}\n</style>\n\n<div class=\"content l-page\">\n <a href=\"/\" class=\"logo\">\n " + logo + "\n Distill\n </a>\n <div class=\"nav\">\n </div>\n</div>\n";
var header = function(dom, data) { var header = function(dom, data) {
dom.querySelector('dt-header').innerHTML = html$1; var el = dom.querySelector("dt-header");
if(el) {
el.innerHTML = html$1;
} else {
var header = dom.createElement("dt-header");
header.innerHTML = html$1;
var b = dom.querySelector("body");
b.insertBefore(header, b.firstChild);
}
}; };
var html$2 = "\n<style>\n dt-appendix {\n display: block;\n font-family: \"Open Sans\";\n font-size: 14px;\n line-height: 24px;\n margin-bottom: 0;\n border-top: 1px solid rgba(0,0,0,0.1);\n color: rgba(0,0,0,0.5);\n background: rgba(0,0,0,0.025);\n padding-top: 36px;\n padding-right: 24px;\n padding-bottom: 60px;\n padding-left: 24px;\n }\n dt-appendix h3 {\n font-size: 16px;\n font-weight: 500;\n margin-top: 18px;\n margin-bottom: 18px;\n color: rgba(0,0,0,0.65);\n }\n dt-appendix .citation {\n font-size: 11px;\n line-height: 15px;\n border-left: 1px solid rgba(0, 0, 0, 0.1);\n padding-left: 18px;\n border: 1px solid rgba(0,0,0,0.1);\n background: rgba(0, 0, 0, 0.02);\n padding: 10px 18px;\n border-radius: 3px;\n color: rgba(150, 150, 150, 1);\n overflow: hidden;\n margin-top: -12px;\n }\n dt-appendix .references {\n font-size: 12px;\n line-height: 20px;\n }\n dt-appendix a {\n color: rgba(0, 0, 0, 0.6);\n }\n</style>\n\n<div class=\"l-body\">\n <h3>References</h3>\n <dt-bibliography></dt-bibliography>\n <h3 id=\"citation\">Errors, Reuse, and Citation</h3>\n <p>If you see mistakes or want to suggest changes, please submit a pull request on <a class=\"github\">github</a>.</p>\n <p>Diagrams and text are licensed under Creative Commons Attribution <a href=\"https://creativecommons.org/licenses/by/2.0/\">CC-BY 2.0</a>, unless noted otherwise, with the source available on available on <a class=\"github\">github</a>. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: “Figure from …”.</p>\n <p>For attribution in academic contexts, please cite this work as</p>\n <pre class=\"citation short\"></pre>\n <p>BibTeX citation</p>\n <pre class=\"citation long\"></pre>\n</div>\n"; var html$2 = "\n<style>\n dt-appendix {\n display: block;\n font-family: \"Open Sans\";\n font-size: 14px;\n line-height: 24px;\n margin-bottom: 0;\n border-top: 1px solid rgba(0,0,0,0.1);\n color: rgba(0,0,0,0.5);\n background: rgba(0,0,0,0.025);\n padding-top: 36px;\n padding-right: 24px;\n padding-bottom: 60px;\n padding-left: 24px;\n }\n dt-appendix h3 {\n font-size: 16px;\n font-weight: 500;\n margin-top: 18px;\n margin-bottom: 18px;\n color: rgba(0,0,0,0.65);\n }\n dt-appendix .citation {\n font-size: 11px;\n line-height: 15px;\n border-left: 1px solid rgba(0, 0, 0, 0.1);\n padding-left: 18px;\n border: 1px solid rgba(0,0,0,0.1);\n background: rgba(0, 0, 0, 0.02);\n padding: 10px 18px;\n border-radius: 3px;\n color: rgba(150, 150, 150, 1);\n overflow: hidden;\n margin-top: -12px;\n }\n dt-appendix .references {\n font-size: 12px;\n line-height: 20px;\n }\n dt-appendix a {\n color: rgba(0, 0, 0, 0.6);\n }\n</style>\n\n<div class=\"l-body\">\n <h3>References</h3>\n <dt-bibliography></dt-bibliography>\n <h3 id=\"citation\">Errors, Reuse, and Citation</h3>\n <p>If you see mistakes or want to suggest changes, please submit a pull request on <a class=\"github\">github</a>.</p>\n <p>Diagrams and text are licensed under Creative Commons Attribution <a href=\"https://creativecommons.org/licenses/by/2.0/\">CC-BY 2.0</a>, unless noted otherwise, with the source available on available on <a class=\"github\">github</a>. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: “Figure from …”.</p>\n <p>For attribution in academic contexts, please cite this work as</p>\n <pre class=\"citation short\"></pre>\n <p>BibTeX citation</p>\n <pre class=\"citation long\"></pre>\n</div>\n";
@@ -4380,7 +4388,14 @@ var html$3 = "\n<style>\ndt-footer {\n display: block;\n color: rgba(255, 255,
var footer = function(dom, data) { var footer = function(dom, data) {
var el = dom.querySelector("dt-footer"); var el = dom.querySelector("dt-footer");
if(el) { el.innerHTML = html$3; } if(el) {
el.innerHTML = html$3;
} else {
var footer = dom.createElement("dt-footer");
footer.innerHTML = html$3;
var b = dom.querySelector("body");
b.appendChild(footer);
}
}; };
var citation = function(dom, data) { var citation = function(dom, data) {
@@ -4393,12 +4408,10 @@ var citation = function(dom, data) {
}*/ }*/
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite")); var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
console.log(citeTags);
citeTags.forEach(function (el) { citeTags.forEach(function (el) {
var key = el.getAttribute("key"); var key = el.getAttribute("key");
if (key) { if (key) {
var keys = key.split(","); var keys = key.split(",");
console.log(keys);
var cite_string = inline_cite_short(keys); var cite_string = inline_cite_short(keys);
el.innerHTML = cite_string; el.innerHTML = cite_string;
} }
@@ -6645,13 +6658,14 @@ var code$1 = function(dom, data) {
var generateCrossref = function(data) { var generateCrossref = function(data) {
if (data.published == undefined) { if (data.published == undefined) {
console.warn("Can't generate XML for post ", data.title, "with data", data); //console.warn("Can't generate XML for post ", data.title, "with data", data);
return ""; //return "";
data.published = new Date("invalid");
} }
var date = data.published; var date = data.published;
var batch_timestamp = Math.floor(Date.now() / 1000); var batch_timestamp = Math.floor(Date.now() / 1000);
var batch_id = data.authors[0].lastName.split(" ")[0].toLowerCase().slice(0,20); var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
batch_id += "_" + date.getFullYear(); batch_id += "_" + date.getFullYear();
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp; batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
// generate XML // generate XML
@@ -6812,16 +6826,16 @@ function renderOnLoad(dom, data) {
markdown(dom, data); markdown(dom, data);
code$1(dom, data); code$1(dom, data);
citation(dom, data); citation(dom, data);
// TODO remove script tag
} }
// If we are in a browser, render automatically. // If we are in a browser, render automatically.
if(window && window.document) { if(window && window.document) {
var data = data || {}; var data = {};
renderImmediately(window.document); renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", function (event) { window.document.addEventListener("DOMContentLoaded", function (event) {
renderOnLoad(window.document, data); renderOnLoad(window.document, data);
console.log("final data:"); generateCrossref(data);
for (var k in data) {console.log(" ", k, ": ", data[k]);}
}); });
} }
+1 -1
View File
File diff suppressed because one or more lines are too long
-4
View File
@@ -1,10 +1,8 @@
<!doctype html> <!doctype html>
<meta charset="utf8"> <meta charset="utf8">
<script src="../dist/template.js"></script> <script src="../dist/template.js"></script>
<script type="text/front-matter"> <script type="text/front-matter">
title: Article Title title: Article Title
description: Description of the post
published: Jan 10, 2017 published: Jan 10, 2017
authors: authors:
- Chris Olah: http://colah.github.io - Chris Olah: http://colah.github.io
@@ -14,7 +12,6 @@
- Google Brain: http://g.co/brain - Google Brain: http://g.co/brain
</script> </script>
<dt-header></dt-header>
<dt-article> <dt-article>
<script type="text/article"></script> <script type="text/article"></script>
<h1>Hello World</h1> <h1>Hello World</h1>
@@ -36,4 +33,3 @@
<h3>Contributions</h3> <h3>Contributions</h3>
<p>List of who did what</p> <p>List of who did what</p>
</dt-appendix> </dt-appendix>
<dt-footer></dt-footer>
+1 -3
View File
@@ -17,7 +17,6 @@
} }
</style> </style>
<dt-header></dt-header>
<dt-article> <dt-article>
<h1>How to Create a Distill Article</h1> <h1>How to Create a Distill Article</h1>
<h2>A collection of examples and best practices for creating interactive explanatory articles using the Distill web framework</h2> <h2>A collection of examples and best practices for creating interactive explanatory articles using the Distill web framework</h2>
@@ -29,7 +28,7 @@
&lt;!doctype html&gt; &lt;!doctype html&gt;
&lt;meta charset="utf-8"&gt; &lt;meta charset="utf-8"&gt;
&lt;script src="../dist/template.min.js"&gt;&lt;/script&gt; &lt;script src="../dist/template.min.js"&gt;&lt;/script&gt;
&lt;dt-article&gt; &lt;dt-article&gt;
&lt;h1&gt;Hello World&lt;/h1&gt; &lt;h1&gt;Hello World&lt;/h1&gt;
&lt;/dt-article&gt; &lt;/dt-article&gt;
@@ -175,4 +174,3 @@
<h2>Including External Files</h2> --> <h2>Including External Files</h2> -->
</dt-article> </dt-article>
<dt-footer></dt-footer>
+3 -3
View File
@@ -28,16 +28,16 @@ function renderOnLoad(dom, data) {
markdown(dom, data); markdown(dom, data);
code(dom, data); code(dom, data);
citation(dom, data); citation(dom, data);
// TODO remove script tag
} }
// If we are in a browser, render automatically. // If we are in a browser, render automatically.
if(window && window.document) { if(window && window.document) {
let data = data || {}; let data = {};
renderImmediately(window.document); renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", (event) => { window.document.addEventListener("DOMContentLoaded", (event) => {
renderOnLoad(window.document, data); renderOnLoad(window.document, data);
console.log("final data:"); generateCrossref(data);
for (var k in data) {console.log(" ", k, ": ", data[k])}
}); });
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "distill-template", "name": "distill-template",
"version": "0.0.13", "version": "0.0.16",
"description": "Template for creating Distill articles.", "description": "Template for creating Distill articles.",
"main": "dist/template.js", "main": "dist/template.js",
"scripts": { "scripts": {