Compare commits

..

6 Commits

Author SHA1 Message Date
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
Shan Carter 60cf026b88 0.0.13 2017-01-09 17:32:05 -08:00
Shan Carter b30d4084ef fix 2017-01-09 17:32:04 -08:00
8 changed files with 78 additions and 64 deletions
+1
View File
@@ -10,6 +10,7 @@ export default function(dom, data) {
// Homepage
//data.homepage = !post.noHomepage;
data.journal = data.journal || {};
// Dates
// TODO: fix updated date
+25 -24
View File
@@ -1,33 +1,34 @@
import ymlParse from "js-yaml";
export default function(dom, data) {
let localData = {};
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) {
let text = el.textContent;
let 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;
});
localData = ymlParse.safeLoad(text);
}
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;
});
}
+5 -3
View File
@@ -3,13 +3,15 @@
export default function(data) {
if (data.published == undefined) {
console.warn("Can't generate XML for post ", data.title, "with data", data);
return "";
//console.warn("Can't generate XML for post ", data.title, "with data", data);
//return "";
data.published = new Date("invalid");
}
var date = data.published;
var batch_timestamp = Math.floor(Date.now() / 1000);
var batch_id = data.authors[0].lastName.split(" ")[0].toLowerCase().slice(0,20);
console.log(data.authors)
var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
batch_id += "_" + date.getFullYear();
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
// generate XML
-1
View File
@@ -5,7 +5,6 @@ export default function(dom) {
let head = dom.querySelector("head");
if (!dom.querySelector("meta[charset]")) {
let meta = dom.createElement("meta");
meta.setAttribute("charset", "utf-8");
+42 -31
View File
@@ -11,7 +11,6 @@ var html = function(dom) {
var head = dom.querySelector("head");
if (!dom.querySelector("meta[charset]")) {
var meta = dom.createElement("meta");
meta.setAttribute("charset", "utf-8");
@@ -283,6 +282,8 @@ function Type$2(tag, options) {
var type = Type$2;
/*eslint-disable max-len*/
var common$4 = common$1;
var YAMLException$3 = exception;
var Type$1 = type;
@@ -894,6 +895,8 @@ function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/*eslint-disable no-bitwise*/
var NodeBuffer;
try {
@@ -1351,6 +1354,8 @@ var default_full = Schema$6.DEFAULT = new Schema$6({
]
});
/*eslint-disable max-len,no-use-before-define*/
var common = common$1;
var YAMLException$1 = exception;
var Mark = mark;
@@ -2942,6 +2947,8 @@ var loader$1 = {
safeLoad: safeLoad_1
};
/*eslint-disable no-use-before-define*/
var common$7 = common$1;
var YAMLException$5 = exception;
var DEFAULT_FULL_SCHEMA$2 = default_full;
@@ -3812,35 +3819,36 @@ var yaml = jsYaml;
var index = yaml;
var frontMatter = function(dom, data) {
var localData = {};
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) {
var text = el.textContent;
var 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;
});
localData = index.safeLoad(text);
}
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) {
@@ -4234,6 +4242,7 @@ var expandData = function(dom, data) {
// Homepage
//data.homepage = !post.noHomepage;
data.journal = data.journal || {};
// Dates
// TODO: fix updated date
@@ -6644,13 +6653,15 @@ var code$1 = function(dom, data) {
var generateCrossref = function(data) {
if (data.published == undefined) {
console.warn("Can't generate XML for post ", data.title, "with data", data);
return "";
//console.warn("Can't generate XML for post ", data.title, "with data", data);
//return "";
data.published = new Date("invalid");
}
var date = data.published;
var batch_timestamp = Math.floor(Date.now() / 1000);
var batch_id = data.authors[0].lastName.split(" ")[0].toLowerCase().slice(0,20);
console.log(data.authors);
var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
batch_id += "_" + date.getFullYear();
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
// generate XML
@@ -6811,16 +6822,16 @@ function renderOnLoad(dom, data) {
markdown(dom, data);
code$1(dom, data);
citation(dom, data);
// TODO remove script tag
}
// If we are in a browser, render automatically.
if(window && window.document) {
var data = data || {};
var data = {};
renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", function (event) {
renderOnLoad(window.document, data);
console.log("final data:");
for (var k in data) {console.log(" ", k, ": ", data[k]);}
generateCrossref(data);
});
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -28,16 +28,16 @@ function renderOnLoad(dom, data) {
markdown(dom, data);
code(dom, data);
citation(dom, data);
// TODO remove script tag
}
// If we are in a browser, render automatically.
if(window && window.document) {
let data = data || {};
let data = {};
renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", (event) => {
renderOnLoad(window.document, data);
console.log("final data:");
for (var k in data) {console.log(" ", k, ": ", data[k])}
generateCrossref(data);
});
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "distill-template",
"version": "0.0.12",
"version": "0.0.15",
"description": "Template for creating Distill articles.",
"main": "dist/template.js",
"scripts": {