Last active
May 22, 2018 19:56
-
-
Save Drew-S/afee843d64b3193a975e8c3669962f49 to your computer and use it in GitHub Desktop.
Relaxedjs: Citations and Bibliography working example APA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include templates | |
script(src='https://cdn.rawgit.com/larsgw/citation.js/archive/citation.js/citation-0.3.4.min.js') | |
+cite('Q21972834', '23-25') | |
+bibliography('citation-apa') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mixin cite(key, number=null) | |
span(data-key=key, data-page=number).citation | |
mixin bibliography(format) | |
h1 Bibliography | |
div(data-format=format)#bibliography | |
script. | |
const Cite = require('citation-js') | |
var data = new Cite() | |
var bibliography = document.getElementById('bibliography') | |
for (var i of document.getElementsByClassName('citation')) { | |
let key = i.getAttribute('data-key') | |
let pg = i.getAttribute('data-page') | |
data.add(key) | |
for (var j of data.data) { | |
if (j.id == key) { | |
if(pg != null) { | |
i.innerHTML = `(${j.author[0].family}, ${j.issued["date-parts"][0][0]}, p. ${pg})` | |
} else { | |
i.innerHTML = `(${j.author[0].family}, ${j.issued["date-parts"][0][0]})` | |
} | |
} | |
} | |
} | |
var output = data.get({ | |
format: 'string', | |
type: 'html', | |
style: bibliography.getAttribute('data-format'), | |
lange: 'en-US' | |
}) | |
bibliography.innerHTML = output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment