Fixing edge cases with missing tags and data

This commit is contained in:
Shan Carter
2017-01-06 16:20:04 -08:00
parent 037996bd06
commit 6b93782533
8 changed files with 70 additions and 60 deletions
+22 -22
View File
@@ -2,28 +2,28 @@ import bibtexParse from "bibtex-parse-js";
export default function(dom, data) {
let el = dom.querySelector('script[type="text/bibliography"]');
//TODO If we don't have a local element, make a request for the document.
let rawBib = el.textContent;
console.log(rawBib, bibtexParse.toJSON(rawBib))
let bibliography = {};
bibtexParse.toJSON(rawBib).forEach(e => {
bibliography[e.citationKey] = e.entryTags;
bibliography[e.citationKey].type = e.entryType;
});
let citations = {};
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
citeTags.forEach(el => {
let citationKeys = el.getAttribute("key").split(",");
citationKeys.forEach(key => {
if (bibliography[key]) {
citations[key] = bibliography[key];
} else {
console.warn("No bibliography entry found for: " + key);
}
if (el) {
let rawBib = el.textContent;
let bibliography = {};
bibtexParse.toJSON(rawBib).forEach(e => {
bibliography[e.citationKey] = e.entryTags;
bibliography[e.citationKey].type = e.entryType;
});
});
data.citations = citations;
console.log(data.citations)
let citations = {};
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
citeTags.forEach(el => {
let citationKeys = el.getAttribute("key").split(",");
citationKeys.forEach(key => {
if (bibliography[key]) {
citations[key] = bibliography[key];
} else {
console.warn("No bibliography entry found for: " + key);
}
});
});
data.citations = citations;
}
}
+7 -5
View File
@@ -1,9 +1,11 @@
export default function(dom, data) {
let citations = Object.keys(data.citations).map(c => data.citations[c]);
citations.sort((a, b) => {
return a.author.localeCompare(b.author);
});
let citations = [];
if (data.citations) {
citations = Object.keys(data.citations).map(c => data.citations[c]);
citations.sort((a, b) => {
return a.author.localeCompare(b.author);
});
}
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
citeTags.forEach(el => {
+20 -18
View File
@@ -4,24 +4,26 @@ export default function(dom, data) {
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);
let text = el.textContent;
let localData = ymlParse.safeLoad(text);
data.title = localData.title;
data.description = localData.description;
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;
data.description = localData.description;
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;
});
}
+10 -7
View File
@@ -1,6 +1,6 @@
export default function(dom, data) {
let head = dom.querySelector("head");
appendHtml(head, `
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<link rel="icon" type="image/png" href="/favicon.png">
@@ -62,12 +62,15 @@ export default function(dom, data) {
`)
});
Object.keys(data.citations).forEach(key => {
console.log(key);
appendHtml(head, `
<meta name="citation_reference" content="${citation_meta_content(data.citations[key])}" >
`);
});
if (data.citations) {
let citationKeys = Object.keys(data.citations);
citationKeys.forEach(key => {
console.log(key);
appendHtml(head, `
<meta name="citation_reference" content="${citation_meta_content(data.citations[key])}" >
`);
});
}
}
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+6
View File
@@ -1,3 +1,5 @@
<!doctype html>
<meta charset="utf8">
<script src="../dist/template.min.js"></script>
<script type="text/front-matter">
@@ -29,4 +31,8 @@
year={2015}
}
</script>
<dt-appendix>
<h3>Contributions</h3>
<p>List of who did what</p>
</dt-appendix>
<dt-footer></dt-footer>
+1 -4
View File
@@ -1,3 +1,4 @@
<!doctype html>
<meta charset="utf-8">
<script src="../dist/template.min.js"></script>
<style>
@@ -176,8 +177,4 @@
<h2>Including External Files</h2>
</dt-article>
<dt-appendix>
<h3>Contributions</h3>
<p>List of who did what</p>
</dt-appendix>
<dt-footer></dt-footer>