【问题标题】:Jekyll on Github Pages: how to include external content inside footnotes?Github Pages 上的 Jekyll:如何在脚注中包含外部内容?
【发布时间】:2018-11-01 05:09:09
【问题描述】:

由于 Jekyll-Scholar 在 Github 页面上不可用,我正在尝试找到一种解决方法来获得某种参考书目功能,使用 kramdown 脚注和包含。我想留在 Github Pages 工作流程中,而不是在本地编译网站。

我有一个集合,其中包含 _data/biblio.yaml 中的所有引用:

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

page1.md 我有:

This is a sentence with a citation[^1]

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

_includes/citation.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>

这是行不通的,因为在编译后引用是在 before 而不是 inside 脚注定义中呈现的:

<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>

想要的结果显然是在 &lt;li&gt; 块中包含包含的内容。

这不起作用有什么原因吗?有没有办法让它按需要工作?

【问题讨论】:

    标签: jekyll github-pages


    【解决方案1】:

    _includes/citation.html 中,您的assign 语句引入了一个无用的换行符,这会破坏kramdown 解析。

    你可以去掉assign和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>
    

    使用新液体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>
    

    【讨论】:

    • 我实施了您的第二个解决方案,效果很好!非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2013-12-16
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多