【问题标题】:GitHub Pages won't render Jekyll includeGitHub Pages 不会渲染 Jekyll 包含
【发布时间】:2013-03-08 02:18:58
【问题描述】:

我的_includes/ 中有一些液体标记,可以在我的机器上很好地呈现,但是当我推送到gh-pages 时,只有包含的 div 呈现。它应该为我的网站生成导航,按页面类别分组。我已经匹配了我机器上的 ruby​​gems 来模仿我看到的 here。我的流动语法是否有什么问题导致它无法在 GitHub Pages 中呈现?

<!-- NAVBAR -->
<div class="navbar">
{% assign categories = site.pages | map: 'to_liquid' | map: 'category' %}
{% assign usedCategories = '' %}
{% for category in categories %}{% if category %}
    {% capture categoryToCheck %},{{ category }},{% endcapture %}
    {% unless usedCategories contains categoryToCheck %}
    <h3 style="color: red; text-transform: capitalize;">{{ category | replace: '-', ' ' }}</h3>
        {% for doc in site.pages %}{% if doc.category == category %}
        <a href="{{ site.baseurl }}{{ doc.url }}">{{ doc.title }}</a>
        {% endif %}{% endfor %}
        {% capture usedCategories %}{{ usedCategories }}{{ categoryToCheck }}{% endcapture %}
    {% endunless %}
{% endif %}{% endfor %}
</div>

注意:我认为我已将问题归结为map: 'category',因为site.pages | map: 'to_liquid' 生成相同的输出(但顺序不同)。 map: 'category' 在我的机器上从液体中提取字段,但在 gh-pages 上不会发生这种情况。如果您有任何建议,请告诉我!

【问题讨论】:

  • 哈哈哈哈!随意提出一个更简洁的解决方案,以使类别数组在液体中不同:p

标签: html jekyll liquid github-pages


【解决方案1】:

我通过不使用 map 属性来解决这个问题。这是一个sn-p:

{% assign usedCategories = '' %}
{% for page in site.pages %}
  {% unless usedCats contains page.category %}
    <h3 style="color: red; text-transform: capitalize;">{{ page.category | replace: '-', ' ' }}</h3>
  {% capture usedCategories %}{{ usedCategories }}{{page.category}}{% endcapture %}
  {% endunless %}
{% endfor %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多