mirror of
https://github.com/wassname/template.git
synced 2026-06-28 15:23:56 +08:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
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;
|
|
}
|