martin
martin

Reputation: 123

Jekyll on Github Pages: how to include external content inside footnotes?

As Jekyll-Scholar is not available on Github Pages, I am trying to find a workaround to have some kind of bibliography features, using kramdown footnotes and include. I would like to stay in the Github Pages workflow and not to compile the website locally.

I have a collection with all references in _data/biblio.yaml:

- authors: Me, Her and Him
  title: A Serious Article
  key: ref1

In page1.md I have:

This is a sentence with a citation[^1]

[^1]: 
    {% include citation.html key="ref1" %}

And in _includes/citation.html I have a template for citations:

{% assign citation = site.data.biblio | where:"key", include.key | first %}
<span class="cit-authors">{{citation.authors}}</span>, <span class="cit-title">{{citation.title}}</span>

This does not work, as after compilation the citation is rendered before and not inside the footnote definition:

<p>
<span class="cit-authors">Me, Her and Him</span>, <span class="cit-title">A Serious Article</span>
</p>

<div class="footnotes">
  <ol>
    <li id="fn:1">
      <p><a href="#fnref:1" class="reversefootnote">&#8617;</a></p>
    </li>
  </ol>
</div>

The desired result is obviously to have the included content inside the <li> block.

Is there a reason why this does not work? Is there any way to make it work as desired?

Upvotes: 5

Views: 609

Answers (1)

David Jacquel
David Jacquel

Reputation: 52789

In _includes/citation.html, your assign statement introduces a useless line break, which breaks kramdown parsing.

You can remove the line break between assign and html

{% assign citation = site.data.biblio | where:"key", include.key | first %}<span class="cit-authors">{{citation.authors}}</span>, <span class="cit-title">{{citation.title}}</span>

or use the new liquid whitespace control ({%- tag -%})

{%- assign citation = site.data.biblio | where:"key", include.key | first -%}
<span class="cit-authors">{{citation.authors}}</span>, <span class="cit-title">{{citation.title}}</span>

Upvotes: 3

Related Questions