{% assign tags = "all" %} {% for post in site.posts %} {% for tag in post.tags %} {% unless tags contains tag %} {% capture tags %}{{ tags }}|{{ tag }}{% endcapture %} {% endunless %} {% endfor %} {% endfor %} {% assign alltags = tags | split: '|' %} github_category_index.html --- layout: page ---
{% for post in site.categories[page.category] %}

{{ post.title }}

{% if post.subtitle %}

{{ post.subtitle }}

{% endif %}
{{ post.content | truncatewords: 20 | strip_html | xml_escape}} [Read More]
{% endfor %}
github_tag_index.html --- layout: page ---
{% for post in site.tags[page.tag] %}

{{ post.title }}

{% if post.subtitle %}

{{ post.subtitle }}

{% endif %}
{{ post.content | truncatewords: 20 | strip_html | xml_escape}} [Read More]
{% endfor %}
js 获取 liquid 变量方法: 1. 先给 html里 那个变量加上个 id/或者class 2. js 里 先定义变量 . 3. 然后输出就可以了.... {% capture tags %} {% for tag in site.tags %} {{ tag[0] }} {% endfor %} {% endcapture %} {% assign sortedtags = tags | split:' ' | sort %} {% for tag in sortedtags %}

{{ tag }}

{% endfor %} {% capture tags %} {% for tag in site.tags %} {{ tag[0] }} {% endfor %} {% endcapture %} {% assign sortedtags = tags | split:' ' | sort %} {% for tag in sortedtags %} {{ tag }}
{% endfor %} This will generate a list of links like this: 逻辑操作 如下例,可以通过条件语句调整输出结果,只有当 show_heading 为 true 时才显示

: --- heading: I like cupcakes show_heading: true --- ... {% if page.show_heading %}

{{ page.heading | upcase | truncate: 8 }}

{% endif %} ... 下例增加了 elsif 语句进行多个条件的判断,当 show_heading 不为真时,判断 heading 中是否包含 “cupcake”: --- heading: I like cupcakes show_heading: false --- ... {% if page.show_heading %}

{{ page.heading | upcase | truncate: 8 }}

{% elsif page.heading contains "cupcake" %}

I want cupcakes

{% else %}

I don't want cupcakes

{% endif %} ... 除了 if 外,Liquid 中的 for 循环也很简单: --- heading: I like cupcakes show_heading: false cupcakes: - chocolate - lemon - strawberry --- ... ... 上面,将 front matter 中定义的 “cupcakes” 循环输出到列表中。另外 case 也是支持的:

{% case cupcake.rating %} {% when 1 %} {% when 2 %} {% when 3 %} {% when 4 %} {% when 5 %} {% endcase %}

LIQUID 中的 FILTER 下表是 Liquid 中常用的 filter,你也可以访问 Jekyll Cheat Sheet 查看所有可用的 filter 及样例。 filter 输出 {{ "cupcake" | prepend: "chocolate " }} chocolate cupcake {{ "lemon" | append: " cake" }} lemon cake {{ "i like cupcakes" | capitalize }} I like cupcakes {{ "BakeryStore" | downcase }} bakerystore {{ "apple pie" | upcase }} APPLE PIE {{ "muffin&cupcake?" | cgi_escape }} muffin%26cupcake%3F {{ "

Banana Split

" | escape }}

Banana Split

{{ "blueberry muffin.html" | slugify }} blueberry-muffin-html {{ "

Greentea cheesecake

" | strip_html }} Greentea cheesecake {{ "**Sour dough** bread" | markdownify }} Sour dough bread {{ "I really really like cupcakes" | remove_first: 'really' }} I really like cupcakes {{ "I really really like cupcakes" | remove: 'really' }} I like cupcakes {{ "I really really like cupcakes" | replace_first: "really", "truly" }} I truly really like cupcakes {{ "I really really like cupcakes" | replace: "really", "truly" }} I truly truly like cupcakes {{ "Carrot cake" | size }} 11 {{ "Peanut butter cheesecake" | number_of_words }} 3 {{ "Souffle" | slice: 0 }} S {{ "Souffle" | slice: 1 }} o {{ "Souffle" | slice: -2 }} l {{ "Souffle" | slice: 2,4 }} uffl {{ "apple,banana,carrot" | split:"," | jsonify }} [“apple”,”banana”,”carrot”] {{ "The freshest bread in San Francisco" | truncate: 15 }} The freshest… {{ "Who ate all the cupcakes?" | truncatewords: 3 }} Who ate all… 上面这个网页中,不同图片使用了不同的 filter 样式,我们可以结合 Liquid 中的 cycle 和 for 循环实现: --- layout: page title: Muffins ---

Our cupcakes

{% for cupcake in site.cupcakes %}
{{ cupcake.type }}

{{ cupcake.type }}

{{ cupcake.description }}

{% endfor %}
通过 forloop.index 还能获得当前循环的次数: ...

{{ forloop.index }}. {{ cupcake.type }}

如果要从 “0” 还是计数,可以改为: ...

{{ forloop.index0 }}. {{ cupcake.type }}

... 另外,可以使用 reversed 使 for 循环逆向进行: ... {% for cupcake in site.cupcakes reversed %} ... 要限制 for 循环的输出个数可以使用 limit,而要跳过前 x 个输出可以使用 offset: ... {% for cupcake in site.cupcakes reversed limit: 3 offset: 3 %} ... {{testpara}} {% assign xujian = site.tags %} {% capture test %} {{ "site.tags" | append: ".Jekyll" }} {% endcapture %} test: {{ test }} {% for cab in test %} {{cab.title}} {% endfor %}
哈哈 {% for ca in site.tags.AJAX %} {{ca.title}} {% endfor %}
爸爸
xx
哈哈哈

for tagName in site.tags

{{ tagName | first }}

endfor

if(window.location.hash) { var tag = window.location.hash.split('#')[1]; console.log(tag); // 丫的 这是 一个函数啊... 而不是 jquery的 那个filter?? filter(tag); }
所有标签 ✔︎
{% for tag in site.tags %} {% assign t = tag | first %} {% assign posts = tag | last %} {% endfor %}
coe类标签✔︎
{% for someCate in site.categories.coe %} {{ someCate.tags }}
{% endfor %}



所有类✔︎ testing




所有分类+文件名+url ✔︎
{% for category in site.categories %} 分类:{{ category | first }} 文章数:{{ category | last | size }}
{% endfor %}



各签各文章数 方法1 ✔︎
{% for tag in site.tags %} {% assign TagName = tag | first %} {% assign TagNum = tag | last %} {{TagName | downcase | replace:" ","-" }} has {{ TagNum | size }} posts
{% endfor %}



各签各文章数 方法2 ✔︎
{% for tag in site.tags %} {{ tag[0] }} {{ tag[1].size }} {% endfor %}



code类标签(单标签适用)✔︎
{% for someCate in site.categories.code %} {{ someCate.tags }}
{% endfor %}



code类标签(多标签适用)✗
{% for someCate in site.categories.code %} {{ someCate.tags }}
{% endfor %}



AJAX标签文章名+url ✔︎
{% for ca in site.tags.AJAX %} {{ ca.title }}
{{ ca.url }}
{% endfor %}



Misc标签文章名+url ✔︎
{% for ca in site.tags.Misc %} {{ ca.title }}
{{ ca.url }}
{% endfor %}



各标签文章名+url ✔︎

code类 所有文件名✔︎+URL
{% for ca in site.categories.code %} {{ ca.title }} {% endfor %}



所有标签✔︎
{% for tag in site.tags %} {{tag | first }}
{% endfor %}


tagDiv: div1: 全部标签 class: tags-container; id: all-tagsContainer div2: 某类标签 class: tags-container hidden; id: 某类-tagsContainer. 全部标签.点击 触发 对应的tag. 隐藏filename 下 所有的 blog-list-container . 显示某签-container . filenameDiv: div1: 全部文章名 class: blog-list-container; id: all-container div2: 某签文章名 class: blog-list-container hidden; id: 某签-container {% assign finalTags = "all" %} {% for cate in site.categories %} {% assign Ca = cate | first %} {% assign PP = cate | last %}
{% for A in PP %} {% if A.categories contains Ca %} {% unless finalTags contains A.tags %} {% capture finalTags %} {{ finalTags }}|{{ A.tags }} {% endcapture %} {% endunless %}
div2:{{ A.tags }}

{% endif %} {% endfor %}
{% endfor %} {% for cate in site.categories %} {% assign Ca = cate | first %} {% assign PP = cate | last %}
{% for A in PP %} {% if A.categories contains Ca %}
div2:{{ A.tags }}

{% capture capturedTag %} {{A.tags}} {% endcapture %} {% endif %} {% endfor %}
{% endfor %} {% for A in site.categories %} {% assign A1 = A | first %}
循环类:{{A1}}
{% for B in site.tags %} {% assign B1 = B | first %} {% assign B2 = B | last %} {% for C in B2 %} {% capture xxoo %} {% if C.categories contains A1 %} {{ B1 }} {% endif %} {% endcapture %} {% endfor %} {{ xxoo }} {% endfor %} {% endfor %} ★★★★★ 这段可用. 每个类下 的标签.
{% unless xxoo == '' %} div2:{{xxoo}}
{% endunless %}

{% for A in site.categories %} {% assign A1 = A | first %}
{% for B in site.tags %} {% assign B1 = B | first %} {% assign B2 = B | last %} {% for C in B2 %} {% capture xxoo %} {% if C.categories contains A1 %} {{ B1 }} {% endif %} {% endcapture %} {% endfor %}
{% unless xxoo == '' %} {{xxoo}} {% endunless %}
{% endfor %}
{% endfor %}