forked from dyutibarma/monochrome
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcategories.html
77 lines (70 loc) · 2.48 KB
/
categories.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
72
73
74
75
76
77
---
layout: default
title: Categories
---
{% comment %}
Adapted from https://codinfox.github.io/dev/2015/03/06/use-tags-and-categories-in-your-jekyll-based-github-pages/
Possible license: https://creativecommons.org/licenses/by-nc/4.0/
{% endcomment %}
{% comment %}
=======================
The following part extracts all the tags from your posts and sort tags, so that you do not need to manually collect your tags to a place.
=======================
{% endcomment %}
{% assign rawcategories = "" %}
{% for post in site.posts %}
{% assign tcategories = post.categories | join:'|' | append:'|' %}
{% assign rawcategories = rawcategories | append:tcategories %}
{% endfor %}
{% assign rawcategories = rawcategories | split:'|' | sort %}
{% comment %}
=======================
The following part removes dulpicated tags and invalid tags like blank category.
=======================
{% endcomment %}
{% assign tags = "" %}
{% for category in rawcategories %}
{% if category != "" %}
{% if tags == "" %}
{% assign tags = category | split:'|' %}
{% endif %}
{% unless tags contains category %}
{% assign tags = tags | join:'|' | append:'|' | append:category | split:'|' %}
{% endunless %}
{% endif %}
{% endfor %}
<h2>Categories</h2>
{% comment %}
=======================
The purpose of this snippet is to list all the tags you have in your site.
=======================
{% endcomment %}
{% if tags.size > 0 %}
<p><ul class="tags">{% for category in tags %}<li><a href=#{{ category | slugify }}>{{ category }}</a></li>{% endfor %}</ul></p>
{% endif %}
{% comment %}
=======================
The purpose of this snippet is to list all your posts posted with a certain category.
=======================
{% endcomment %}
<div class="content">
{% for category in tags %}
<h3 id="{{ category | slugify }}">{{ category }}</h3>
<ul class="posts-by-tag">
{% for post in site.posts %}
{% if post.categories contains category %}
<li>
<span class="post-title-by-tag"><a href="{% if site.baseurl == "/" %}{{ post.url }}{% else %}{{ post.url | prepend: site.baseurl }}{% endif %}">{%if post.header %}{{ post.header }}{% else %}{{ post.title }}{% endif %}</a></span>
<time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%-d %B %Y" }}
{% if post.last_modified_at %}
<span> (last update on {{ post.last_modified_at | date: "%-d %B %Y" }})</span>
{% endif %}
</time>
{% if post.categories.size > 0 %}
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</div>