-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.html
71 lines (62 loc) · 2.33 KB
/
blog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
layout: default
title: Blog
---
<h1>{{page.title}}</h1>
{% comment %}
http://stackoverflow.com/a/24744306/1327931
Get all tags and their post count as delimited text, sort the text,
extract individual elements from the sorted text.
Pad post count, so it will sort properly as text.
In addition to sorting by post count, am sorting by tag name for those
with the same post count. In order to simplify this logic, I used the
index in the for loop, and since I wanted largest post count first
I used rindex.
{% endcomment %}
{% capture tags %}
{% for tag in site.tags %}
{{ tag[1].size | plus: 1000 }}#{{ tag[0] | downcase }}#{{ tag[0] }}{% unless forloop.last %}, {% endunless %}
{% endfor %}
{% endcapture %}
{% comment %}
format: nnnn#lower-case-tag#Tag
nnnn = tag count with 4 digits
lower-case-tag = so tag case will not impact sorting
Tag = actual tag text to display
{% endcomment %}
{% assign sorted_tags = tags | split:', ' | sort %}
<p class="post-tags">
{% assign tags = "" %}
{% for unused in sorted_tags %}
{% assign temp = sorted_tags[forloop.rindex0] | split: '#' %}
{% assign count = temp[0] | minus: 1000 %}
{% assign tag = temp[2] | strip %}
{% assign next_index = forloop.rindex0 | minus: 1 %}
{% assign temp = sorted_tags[next_index] | split: '#' %}
{% assign count_next = temp[0] | minus: 1000 %}
{% capture tags %}{{ tags }} {{ tag }}{% endcapture %}
{% if count != count_next or forloop.last %}
{% assign tags = tags | strip | split:' ' %}
{% for unused in tags %}
{% assign tag = tags[forloop.rindex0] | strip %}
<a class="post-tag" href="/blog/tags/{{ tag | slugify }}/" title="{{ count }} posts tagged with “{{ tag }}”">{{ tag }}<span class="post-tag-count">[{{ count }}]</span></a>
{% endfor %}
{% assign tags = "" %}
{% endif %}
{% endfor %}
</p>
{% for post in site.posts %}
{% assign last_year = year %}
{% assign year = post.date | date: "%Y" %}
{% assign next_year = site.posts[forloop.index].date | date: "%Y" %}
{% if forloop.first or year != last_year %}
<section>
<header><h2 id="{{year}}"><a href="/blog/{{year}}/" title="Expand posts in {{ year }}">{{ year }}</a></h2></header>
<ul class="post-list-minimal">
{% endif %}
<li>{% include post-list-minimal.html post=post %}</li>
{% if forloop.last or year != next_year %}
</ul>
</section>
{% endif %}
{% endfor %}