Skip to content

Commit f6bb7d8

Browse files
authored
Use sort_natural instead of custom-logic (mmistakes#2756)
1 parent f5f1a94 commit f6bb7d8

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

_includes/category-list.html

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@
66
{% endcase %}
77

88
{% if site.category_archive.path %}
9-
{% comment %}
10-
<!-- Sort alphabetically regardless of case e.g. a B c d E -->
11-
<!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ -->
12-
{% endcomment %}
13-
{% capture page_categories %}{% for category in page.categories %}{{ category | downcase }}|{{ category }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
14-
{% assign category_hashes = page_categories | split: ',' | sort %}
9+
{% assign categories_sorted = page.categories | sort_natural %}
1510

1611
<p class="page__taxonomy">
1712
<strong><i class="fas fa-fw fa-folder-open" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].categories_label | default: "Categories:" }} </strong>
1813
<span itemprop="keywords">
19-
{% for hash in category_hashes %}
20-
{% assign keyValue = hash | split: '|' %}
21-
{% capture category_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
14+
{% for category_word in categories_sorted %}
2215
<a href="{{ category_word | slugify | prepend: path_type | prepend: site.category_archive.path | relative_url }}" class="page__taxonomy-item" rel="tag">{{ category_word }}</a>{% unless forloop.last %}<span class="sep">, </span>{% endunless %}
2316
{% endfor %}
2417
</span>

_includes/tag-list.html

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@
66
{% endcase %}
77

88
{% if site.tag_archive.path %}
9-
{% comment %}
10-
<!-- Sort alphabetically regardless of case e.g. a B c d E -->
11-
<!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ -->
12-
{% endcomment %}
13-
{% capture page_tags %}{% for tag in page.tags %}{{ tag | downcase }}|{{ tag }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
14-
{% assign tag_hashes = page_tags | split: ',' | sort %}
9+
{% assign tags_sorted = page.tags | sort_natural %}
1510

1611
<p class="page__taxonomy">
1712
<strong><i class="fas fa-fw fa-tags" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].tags_label | default: "Tags:" }} </strong>
1813
<span itemprop="keywords">
19-
{% for hash in tag_hashes %}
20-
{% assign keyValue = hash | split: '|' %}
21-
{% capture tag_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
14+
{% for tag_word in tags_sorted %}
2215
<a href="{{ tag_word | slugify | prepend: path_type | prepend: site.tag_archive.path | relative_url }}" class="page__taxonomy-item" rel="tag">{{ tag_word }}</a>{% unless forloop.last %}<span class="sep">, </span>{% endunless %}
2316
{% endfor %}
2417
</span>

0 commit comments

Comments
 (0)