Package: wagtail-references
Wagtail ReferencesBibTeX based bibliography entries, as wagtail snippetsTemplates"But, where are the templates?!"is a natural question. Answer: There aren't any templates or tags so far...
I run all my wagtail installations in headless mode with a react front end, so can only justify putting in place the
templates for managing the references on wagtail (for now). But see below for how to do it yourself.If you'd like to make a PR with tmplates, I'm very open to collaboration :)I'm gradually improving wagtail admin templates, I'll do an ever-better job as the library gets more traction and users.Bottom line: Star this repo on Github if you use or like it, so I know it's getting traction!Displaying references on the front endWrite your own templates/htmlI usecitation.jsfor parsing and displaying the bibtex
in the wagtail admin, it's usable in-browser (in a template) like this:<!-- Using citation.js https://citation.js.org/api/tutorial-getting_started.html --><scriptsrc="https://cdn.jsdelivr.net/npm/citation-js"type="text/javascript"></script><scripttype="text/javascript">constCite=require('citation-js')functionrenderToDiv(inputBibtex,divId){constcitation=newCite(inputBibtex)constoutputHtml=citation.format('bibliography',{format:'html',template:'apa',lang:'en-US'})outputDiv=document.getElementById(divId)outputDiv.innerHTML=outputHtml}</script><h3><strong>Slug (citation key):</strong>{{ reference.slug }}</h3><h3><strong>Type:</strong>{{ reference.bibtype }}</h3><divid="{{ reference.slug }}"></div><scripttype="text/javascript">renderToDiv("{{ reference.bibtex_string }}","{{ reference.slug }}")</script>Using react (wagtail in headless mode)On the frontend, I use react (see aforementioned nanorant about using wagtail in a headless mode). I'm presently usingreact-citeprocalong withbiblatex-csl-converterin a project and it works out pretty
well. Your component will look like this-ish:importReactfrom'react'import{Bibliography}from'react-citeproc'importrawfrom'raw.macro'import{BibLatexParser,CSLExporter}from'biblatex-csl-converter'conststyle=raw('assets/csl/apa-style.csl')constlocale=raw('assets/csl/xml-locale.xml')classReferenceextendsReact.Component{constructor(props){super(props)this.state={bibtex:undefined,csl:undefined,}}staticgetDerivedStateFromProps(nextProps,prevState){if(nextProps.bibtex!==prevState.bibtex){constparser=newBibLatexParser(nextProps.detail.bibtex,{processUnexpected:false,processUnknown:false})constcsl=newCSLExporter(parser.output).parse()return{bibtex:nextProps.detail.bibtex,csl,}}returnnull}render(){return(<divclassName={classes.bibliography}><Bibliographystyle={style}locale={locale}items={this.state.csl}/></div>)}}exportdefaultReferenceRoadmapI'd like to include:A better snippet editor, possibly using a json editor component and allowing the user to switch between tex and jsonAListSerializerfor serializing out multiple references as a bibjson collectionAn HTML renderer and viewsetRequirementsWagtail References is tested on Django 2.1 or later and Wagtail 2.3 or later.Supported VersionsPython: 3.6Django: 2.1Wagtail: 2.3Getting startedInstalling from pip:pip install wagtail_referencesAdding toINSTALLED_APPS:INSTALLED_APPS=[...'wagtail_references',...]Running the migrations:python manage.py migrate wagtail_referencesReference ModelThere's only one database modelReference, which is registered as a snippet in Wagtail, making it searchable and
selectable.SlugsThe model has a (required, unique)slugfield which is automatically set from bibtex contents when a reference
is added.For example, if you have the following bibtex entry:@article{Clark2017a,
author = {Clark, Thomas H. E. and Lueck, Rolf G. and Hay, Alex E. and Davey, Thomas and Stern, Peter and Horwitz, Rachel},
journal = {Proc. of the 12th European Wave and Tidal Energy Conference},
pages = {7},
title = {{InSTREAM : Measurement , Characterisation and Simulation of Turbulence from Test Tank to Ocean .}},
year = {2017}
}the slug will automatically be set toclark-lueck-hay-davey-stern-horwitz-2017, with an appended-2,-3etc
to maintain uniqueness.The citation key for the bibtex entry will be updated to correspond:@article{clark-lueck-hay-davey-stern-horwitz-2017,
author = ... etc etc ...
}Uniqueness is enforced at form validation and database level. Slugs may be edited manually after creation of a reference.bibtex and bibjsonThe reference model comprises both abibtexfield (containing the bibtex string, raw) and abibjsonfield.Yes, I know this is duplication of data. But I'd rather do that than incur the cost of re-parsing the data every time I
want to serialize it out in a different form. I could've chosen to cache it, but then I don't know how much memory you
folks have, and don't want to screw your cache if you're managing a lot of references). It was a judgement call.
Use-case and an alternative solution? File an issue.Thebibjsonis stored natively as JSON if you have POSTGRES, otherwise as a string (thanks todjango-jsonfield).Django SettingsThe following settings can be defined in yourSETTINGS.py:WAGTAILREFERENCES_CONVERT_BIBTEX(default:False) Before saving new records, the record will be homogenized to
strict latex. This forces a conversion to unicode and, for example, adds braces to force capitalization.WAGTAILREFERENCES_ENABLE_UNICODE(default:True) If enabled, items such as"C{\"o}ze"will be converted to
their unicode equivalents. If you're using entries in a LaTeX rendering engine, this isn't necessary. If you're
using them to rendering HTML (which you probably are, this is a web CMS after all), you probably want this.WAGTAILREFERENCES_COLLECTION_NAME(default:None) Applies a default collection name to records rendered in bibjson form.ExamplesFor your and our testing purposes, it's useful to have some examples to hand, so I've prepared some in theexamples.pyfile, which simply contains a series of different bibtex references.If you encounter awkward references or ones which won't validate, please post them into a github issue so I can help diagnose and add them for test.ThanksThanks are due tointernautfor providing the bibtex-json converter. Their code isn't licensed so I don't know how to credit it other than saying thanks!