我正在嘗試製作按標籤分組的集合中的頁面列表。我知道這是很容易可以與哲基爾的內置site.tags
功能,我可以(有)的東西,如實現:按標籤列出Jekyll Collection頁面
<h3>Tags</h3>
{% for tag in site.tags %}
{% assign t = tag | first %}
{% assign posts = tag | last %}
<h4><a name="{{t | downcase | replace:" ","-" }}"></a><a class="internal" href="/tagged/#{{t | downcase | replace:" ","-" }}">{{ t | downcase }}</a></h4>
<ul>
{% for post in posts %}
{% if post.tags contains t %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
<span class="date">{{ post.date | date: "%B %-d, %Y" }}</span>
</li>
{% endif %}
{% endfor %}
</ul>
<hr>
{% endfor %}
爲了得到這樣的:
我想在名爲note
的集合中複製site.tags
函數。使用YAML標題中的tags: [urban growth, California, industrialization]
,我的收藏中的標記與帖子的標記相同。但我想用集合來代替它。我幾乎可以達到什麼樣的我想有以下:
{% assign collection = site.note | group_by: "tags" | uniq %}
{% for group in collection %}
{% comment %} This is super hacky and I don't like it {% endcomment%}
<h3>{{ group.name | replace: '"', '' | replace: '[', '' | replace: ']', '' }}</h3>
<ul>
{% for item in group.items %}
<li><a href="{{ item.url | prepend: site.baseurl | prepend: site.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>
{%endfor%}
但你很可能會看到,這不破標籤伸到其獨特的羣體;相反,YAML中的每組標籤都被視爲單個大標籤。任何構建唯一標籤數組並在其下列出Collection頁面的指針?
這偉大的工作,謝謝! –