mirror of
https://github.com/wassname/template.git
synced 2026-09-11 12:51:52 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c77fbbd18f | ||
|
|
adcfba4627 | ||
|
|
6ef3847bf6 | ||
|
|
0b68c4ea1f | ||
|
|
60cf026b88 | ||
|
|
b30d4084ef |
@@ -10,6 +10,7 @@ export default function(dom, data) {
|
|||||||
|
|
||||||
// Homepage
|
// Homepage
|
||||||
//data.homepage = !post.noHomepage;
|
//data.homepage = !post.noHomepage;
|
||||||
|
data.journal = data.journal || {};
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
// TODO: fix updated date
|
// TODO: fix updated date
|
||||||
|
|||||||
+25
-24
@@ -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;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
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);
|
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 += "_" + 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
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
Vendored
+42
-31
@@ -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");
|
||||||
@@ -283,6 +282,8 @@ function Type$2(tag, options) {
|
|||||||
|
|
||||||
var type = Type$2;
|
var type = Type$2;
|
||||||
|
|
||||||
|
/*eslint-disable max-len*/
|
||||||
|
|
||||||
var common$4 = common$1;
|
var common$4 = common$1;
|
||||||
var YAMLException$3 = exception;
|
var YAMLException$3 = exception;
|
||||||
var Type$1 = type;
|
var Type$1 = type;
|
||||||
@@ -894,6 +895,8 @@ function createCommonjsModule(fn, module) {
|
|||||||
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*eslint-disable no-bitwise*/
|
||||||
|
|
||||||
var NodeBuffer;
|
var NodeBuffer;
|
||||||
|
|
||||||
try {
|
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 common = common$1;
|
||||||
var YAMLException$1 = exception;
|
var YAMLException$1 = exception;
|
||||||
var Mark = mark;
|
var Mark = mark;
|
||||||
@@ -2942,6 +2947,8 @@ var loader$1 = {
|
|||||||
safeLoad: safeLoad_1
|
safeLoad: safeLoad_1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*eslint-disable no-use-before-define*/
|
||||||
|
|
||||||
var common$7 = common$1;
|
var common$7 = common$1;
|
||||||
var YAMLException$5 = exception;
|
var YAMLException$5 = exception;
|
||||||
var DEFAULT_FULL_SCHEMA$2 = default_full;
|
var DEFAULT_FULL_SCHEMA$2 = default_full;
|
||||||
@@ -3812,35 +3819,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) {
|
||||||
@@ -4234,6 +4242,7 @@ var expandData = function(dom, data) {
|
|||||||
|
|
||||||
// Homepage
|
// Homepage
|
||||||
//data.homepage = !post.noHomepage;
|
//data.homepage = !post.noHomepage;
|
||||||
|
data.journal = data.journal || {};
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
// TODO: fix updated date
|
// TODO: fix updated date
|
||||||
@@ -6644,13 +6653,15 @@ 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);
|
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 += "_" + 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
|
||||||
@@ -6811,16 +6822,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]);}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "distill-template",
|
"name": "distill-template",
|
||||||
"version": "0.0.12",
|
"version": "0.0.15",
|
||||||
"description": "Template for creating Distill articles.",
|
"description": "Template for creating Distill articles.",
|
||||||
"main": "dist/template.js",
|
"main": "dist/template.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user