mirror of
https://github.com/wassname/template.git
synced 2026-07-26 13:37:31 +08:00
Bibliography data working
This commit is contained in:
@@ -73,5 +73,6 @@ const html = `
|
||||
// })
|
||||
|
||||
export default function(dom, data) {
|
||||
dom.querySelector('dt-appendix').innerHTML = html;
|
||||
let el = dom.querySelector('dt-appendix')
|
||||
if (el) el.innerHTML = html;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
data.citations = citations;
|
||||
console.log(data.citations)
|
||||
}
|
||||
@@ -13,13 +13,15 @@ export default function(dom, data) {
|
||||
});
|
||||
|
||||
let bibEl = dom.querySelector("dt-bibliography");
|
||||
let ol = dom.createElement("ol");
|
||||
citations.forEach(citation => {
|
||||
let el = dom.createElement("li");
|
||||
el.textContent = bibliography_cite(citation);
|
||||
ol.appendChild(el);
|
||||
})
|
||||
bibEl.appendChild(ol);
|
||||
if (bibEl) {
|
||||
let ol = dom.createElement("ol");
|
||||
citations.forEach(citation => {
|
||||
let el = dom.createElement("li");
|
||||
el.textContent = bibliography_cite(citation);
|
||||
ol.appendChild(el);
|
||||
})
|
||||
bibEl.appendChild(ol);
|
||||
}
|
||||
|
||||
function inline_cite(key){
|
||||
if (key in data.citations){
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import bibtexParse from "bibtex-parse-js";
|
||||
|
||||
export default function(dom, data) {
|
||||
|
||||
//TODO populate bibliography
|
||||
|
||||
let rawBib = `
|
||||
@article{gregor2015draw,
|
||||
title={DRAW: A recurrent neural network for image generation},
|
||||
author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
|
||||
journal={arXivreprint arXiv:1502.04623},
|
||||
year={2015}
|
||||
}
|
||||
@article{mercier2011humans,
|
||||
title={Why do humans reason? Arguments for an argumentative theory},
|
||||
author={Mercier, Hugo and Sperber, Dan},
|
||||
journal={Behavioral and brain sciences},
|
||||
volume={34},
|
||||
number={02},
|
||||
pages={57--74},
|
||||
year={2011},
|
||||
publisher={Cambridge Univ Press}
|
||||
}`;
|
||||
|
||||
var 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.textContent.split(",");
|
||||
citationKeys.forEach(key => {
|
||||
if (bibliography[key]) {
|
||||
citations[key] = bibliography[key];
|
||||
} else {
|
||||
console.warn("No bibliography entry found for: " + key);
|
||||
}
|
||||
});
|
||||
});
|
||||
data.citations = citations;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import logo from "./distill-logo.svg";
|
||||
|
||||
const html = `
|
||||
let html = `
|
||||
<style>
|
||||
dt-footer {
|
||||
display: block;
|
||||
@@ -38,5 +38,6 @@ dt-footer .logo {
|
||||
`;
|
||||
|
||||
export default function(dom, data) {
|
||||
dom.querySelector('dt-footer').innerHTML = html;
|
||||
let el = dom.querySelector("dt-footer");
|
||||
if(el) el.innerHTML = html;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ import ymlParse from "js-yaml";
|
||||
|
||||
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.
|
||||
|
||||
let text = el.textContent;
|
||||
let localData = ymlParse.load(text);
|
||||
let localData = ymlParse.safeLoad(text);
|
||||
|
||||
data.title = localData.title;
|
||||
data.description = localData.description;
|
||||
@@ -11,12 +14,14 @@ export default function(dom, data) {
|
||||
let a = {};
|
||||
let name = Object.keys(author)[0];
|
||||
let names = name.split(" ");
|
||||
let affiliation = Object.keys(localData.affiliations[i])[0];
|
||||
a.firstName = names.slice(0, names.length - 1).join(" ");
|
||||
a.lastName = names[names.length -1];
|
||||
a.personalURL = author[name];
|
||||
a.affiliation = affiliation;
|
||||
a.afiiliationURL = localData.affiliations[i][affiliation];
|
||||
if(localData.affiliations[i]) {
|
||||
let affiliation = Object.keys(localData.affiliations[i])[0];
|
||||
a.affiliation = affiliation;
|
||||
a.affiliationURL = localData.affiliations[i][affiliation];
|
||||
}
|
||||
return a;
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -18,7 +18,7 @@
|
||||
<h2>A description of the article</h2>
|
||||
<dt-byline></dt-byline>
|
||||
<p>This is the first paragraph of the article.</p>
|
||||
<p>We can also cite <dt-cite article="gregor2015draw"></dt-cite> external publications.</p>
|
||||
<p>We can also cite <dt-cite key="gregor2015draw"></dt-cite> external publications.</p>
|
||||
</dt-article>
|
||||
|
||||
<script type="text/bibliography">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import html from "./components/html";
|
||||
import styles from "./components/styles";
|
||||
import citeData from "./components/cite-data";
|
||||
import frontMatter from "./components/front-matter";
|
||||
import bibliography from "./components/bibliography";
|
||||
import meta from "./components/meta";
|
||||
import header from "./components/header";
|
||||
import appendix from "./components/appendix";
|
||||
@@ -9,15 +10,14 @@ import citation from "./components/citation";
|
||||
import markdown from "./components/markdown";
|
||||
import code from "./components/code";
|
||||
import testData from "./test-data";
|
||||
import frontMatter from "./components/front-matter";
|
||||
|
||||
|
||||
function render(dom, data) {
|
||||
html(dom);
|
||||
styles(dom);
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
citeData(dom, data);
|
||||
frontMatter(dom, data);
|
||||
bibliography(dom, data);
|
||||
meta(dom, data);
|
||||
header(dom, data);
|
||||
appendix(dom, data);
|
||||
|
||||
Reference in New Issue
Block a user