KEJUN BLOG
KeJun
May 27, 2017
阅读本文需要 3 分钟

此博文用于记录研究 jekyll 时遇到的有趣 liquid 语言片段。

统计捐赠

效果:捐赠

  1. _data目录下创建一个名为donate.yml的文件。
  2. 按如下格式填写:
    - name: 张三
      money: 100
    
  3. 在页面中输入
    {% for d in site.data.donate %}
    {% capture allmoney = 0 %}{{ allmoney | plus: d.money }}{% endcapture %}
     <p {{ d.name }}:<b>{{ d.money }}元</b></p>
    {% endfor %}
     <p><b>总金额: {{allmoney}}元</b></p>
    

标签云

效果就是本博客的tag,此外还需要配合js。

这个讲真,真的好累…

{% capture tags %}
  {% for tag in site.tags %}
    {{ tag[0] }}
  {% endfor %}
{% endcapture %}

{% assign sortedtags = tags | split:' ' | sort %}

{% for tag in sortedtags %}
  {% assign index = site.tags[tag] | size %}
  {% assign fontsize = 14 %}
  {% assign color = 125 %}
  {% for i in (1..index) %}
  {% capture fontsize %}{{fontsize | plus:1.5}}{% endcapture %}
  {% endfor %}
  {% for i in (1..index) %}
  {% capture color %}{{ color | minus :15}}{% endcapture %}
  {% endfor %}
      <a id="{{ tag }}"  style="font-size:{{fontsize}}px;color:rgb({{color}},{{color}},{{color}})">{{ tag }}</a>
{% endfor %}

计算文章阅读时间

来源:leonids/_includes/read_time.html

{% assign words = content | number_of_words %}
{% if words < 360 %}
  1 min read
{% else %}
  {{ words | divided_by:180 }} mins read
{% endif %}

有用的站点