Tags Jekyll标签按字母顺序排列,不考虑大小写

Tags Jekyll标签按字母顺序排列,不考虑大小写,tags,jekyll,Tags,Jekyll,我正在用Jekyll写博客,我有一些主题标签(例如:CSS、JavaScript、前端、可访问性等)。我想让它们以字母顺序出现,不管大小写:可访问性、CSS、前端、JavaScript等等 我是杰基尔的新手,但我还没有发现任何能证明这一点的东西。下面是我当前的代码。任何建议都会有帮助 [//]: # (Get the tag name for every tag on the site and set them to the site_tags variable.) {% capture sit

我正在用Jekyll写博客,我有一些主题标签(例如:CSS、JavaScript、前端、可访问性等)。我想让它们以字母顺序出现,不管大小写:可访问性、CSS、前端、JavaScript等等

我是杰基尔的新手,但我还没有发现任何能证明这一点的东西。下面是我当前的代码。任何建议都会有帮助

[//]: # (Get the tag name for every tag on the site and set them to the site_tags variable.)
{% capture site_tags %}{% for tag in site.tags %}{{ tag | first }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}

[//]: # (tag_words is a sorted array of the tag names.)
{% assign tag_words = site_tags | split:',' | sort %}

[//]: # (Build the Page)

[//]: # (List of all tags)
<section>
  <ul>
    {% for item in (0..site.tags.size) %}{% unless forloop.last %}
      {% capture this_word %}{{ tag_words[item] }}{% endcapture %}
      <li>
        <a href="#{{ this_word | cgi_escape }}" class="tag">{{ this_word }}
          <span>({{ site.tags[this_word].size }})</span>
        </a>
      </li>
    {% endunless %}{% endfor %}
  </ul>
</section>

[//]: # (Posts by tags)
<section class="tags">
  {% for item in (0..site.tags.size) %}{% unless forloop.last %}
    {% capture this_word %}{{ tag_words[item] }}{% endcapture %}
    <h3 id="{{ this_word | cgi_escape }}">{{ this_word }}</h3>
    {% for post in site.tags[this_word] %}{% if post.title != null %}
      <div class="row">
        <span>
          <a href="{{ post.url }}">{{ post.title }}</a>
        </span>
        <span class="post-date archive-date">
          {{ post.date | date: "%b %-d, %Y" }}
        </span>
      </div>
    {% endif %}{% endfor %}
  {% endunless %}{% endfor %}
</section>
[//]:#(获取站点上每个标记的标记名,并将其设置为site_tags变量。)
{%capture site_tags%}{%for site.tags%}{{tag | first}{%inspect forloop.last%},{%endinspect%}{%endfor%}{%endcapture%}
[//]:#(tag#words是标记名的排序数组。)
{%assign tag_words=site_tags | split:','| sort%}
[//]:#(构建页面)
[//]:#(所有标记的列表)
    {%(0..site.tags.size)%}{%forloop.last%} {%capture this_word%}{{tag_words[item]}{%endcapture%}
  • {%end除非%}{%endfor%}
[//]:#(按标签发布) {%(0..site.tags.size)%}{%forloop.last%} {%capture this_word%}{{tag_words[item]}{%endcapture%} {{这个词}} {%for site.tags[这个单词]]}{%if post.title!=null%} {post.date | date:“%b%-d,%Y”} {%endif%}{%endfor%} {%end除非%}{%endfor%}
你真的很接近!有一些bug,但其他的都是对的

在制作标记数组的第一部分中,与制作字符串然后将其拆分为数组相比,将其合并为数组更容易一些

// create empty array
{% assign tags = '' | split: '' %}

// iterate through tags, get tag name and make into an array, concat arrays
{% for tag in site.tags %}
    {% assign tagName = tag | first | split: ' ' %}
    {% assign tags = tags | concat: tagName %}
{% endfor %}

// sort tags
{% assign tags = tags | sort %}
现在您已经有了一个标记数组,您可以使用for循环遍历它们。无需迭代
item=0…n
并使用
标记[item]

// create list of tags and number of posts with that tag
<section>
    <ul>
        {% for tag in tags %}
            {% assign postCount = site.tags[tag] | size %}
            <li>
                <a href="#{{ tag | cgi_escape }}" class="tag">
                    {{ tag }}
                    <span>({{ postCount }})</span>
                </a>
            </li>
        {% endfor %}
    </ul>
</section>

// create list of posts per title (posts are newest to oldest)
<section class="tags">
    {% for tag in tags %}
        <h3 id="{{ tag | cgi_escape }}">{{ tag }}</h3>
        {% for post in site.tags[tag] %}
            {% if post.title != null %}
                <div class="row">
                    <span>
                        <a href="{{ post.url }}">{{ post.title }}</a>
                    </span>
                    <span class="post-date archive-date">
                        {{ post.date | date: "%b %-d, %Y" }}
                    </span>
                </div>
            {% endif %}
        {% endfor %}
    {% endfor %}
</section>

//创建标签列表和带有该标签的帖子数量
    {标记%中的标记的%s} {%assign postCount=site.tags[tag]| size%}
  • {%endfor%}
//创建每个标题的帖子列表(帖子从最新到最旧) {标记%中的标记的%s} {{tag}} {%用于站点中的帖子。标记[tag]} {%if post.title!=null%} {post.date | date:“%b%-d,%Y”} {%endif%} {%endfor%} {%endfor%}
还有代替的。

这将需要一个新的不区分大小写的排序过滤器: