Skip to content

Commit b6353bf

Browse files
committed
Enable customized order for collections (resolves sighingnow#123).
1 parent a17eec0 commit b6353bf

4 files changed

Lines changed: 93 additions & 25 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,24 @@ collections:
118118
output: true
119119
sort_by: date
120120
permalink: /:collection/:year-:month-:day-:title:output_ext
121+
others:
122+
output: true
123+
sort_by: date
124+
permalink: /:collection/:year-:month-:day-:title:output_ext
125+
```
126+
127+
An optional `ordered_collections` key can be added to `_config.yaml` to control the order of collections in the sidebar:
128+
129+
```yaml
130+
ordered_collections:
131+
- posts
132+
- pages
133+
- others
121134
```
122135

136+
If not specified, the order of collections would be decided by Jekyll. Note that the key `posts` is a special collection
137+
that indicates the `_posts` pages of Jekyll.
138+
123139
## Extra StyleSheet or Javascript elements
124140

125141
You can add extra CSS or JavaScript references using configuration collections:

_config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ collections:
5353
pages:
5454
output: true
5555
permalink: /:collection/:path/
56+
others:
57+
output: true
58+
permalink: /:collection/:path/
59+
60+
ordered_collections:
61+
- posts
62+
- pages
63+
- others
5664

5765
page_width: 800px
5866

_includes/toc-date.html

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,72 @@
4343

4444
<li class="divider"></li>
4545

46-
{% for collection in site.collections %}
47-
<!-- <p>{{ collection.label }}</p> -->
48-
{% if collection.output %}
49-
{% if collection.label == "posts" %}
50-
{% assign reversed_posts = site[collection.label] | reverse %}
51-
{% else %}
52-
{% assign reversed_posts = site[collection.label] %}
53-
{% endif %}
54-
55-
{% for post in reversed_posts %}
56-
{% if page.url == post.url %}
57-
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
46+
{% if site.ordered_collections %}
47+
{% for label in site.ordered_collections %}
48+
{% assign collection = site.collections | where: "label", label | first %}
49+
<!-- <p>{{ collection.label }}</p> -->
50+
{% if collection.output %}
51+
{% if collection.label == "posts" %}
52+
{% assign reversed_posts = site[collection.label] | reverse %}
5853
{% else %}
59-
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
54+
{% assign reversed_posts = site[collection.label] %}
6055
{% endif %}
61-
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
62-
{{ post.title | escape }}
63-
</a>
64-
{% if site.toc.enabled %}
65-
{% if page.url == post.url %}
66-
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}
56+
57+
{% for post in reversed_posts %}
58+
{% if page.url == post.url %}
59+
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
60+
{% else %}
61+
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
62+
{% endif %}
63+
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
64+
{{ post.title | escape }}
65+
</a>
66+
{% if site.toc.enabled %}
67+
{% if page.url == post.url %}
68+
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}
69+
{% endif %}
6770
{% endif %}
71+
</li>
72+
{% endfor %}
73+
74+
{% if reversed_posts.size > 0 %}
75+
<li class="divider"></li>
76+
{% endif %}
77+
{% endif %}
78+
{% endfor %}
79+
{% else %}
80+
{% for collection in site.collections %}
81+
<!-- <p>{{ collection.label }}</p> -->
82+
{% if collection.output %}
83+
{% if collection.label == "posts" %}
84+
{% assign reversed_posts = site[collection.label] | reverse %}
85+
{% else %}
86+
{% assign reversed_posts = site[collection.label] %}
87+
{% endif %}
88+
89+
{% for post in reversed_posts %}
90+
{% if page.url == post.url %}
91+
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
92+
{% else %}
93+
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
6894
{% endif %}
69-
</li>
70-
{% endfor %}
95+
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
96+
{{ post.title | escape }}
97+
</a>
98+
{% if site.toc.enabled %}
99+
{% if page.url == post.url %}
100+
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}
101+
{% endif %}
102+
{% endif %}
103+
</li>
104+
{% endfor %}
71105

72-
{% if reversed_posts.size > 0 %}
73-
<li class="divider"></li>
106+
{% if reversed_posts.size > 0 %}
107+
<li class="divider"></li>
108+
{% endif %}
74109
{% endif %}
75-
{% endif %}
76-
{% endfor %}
110+
{% endfor %}
111+
{% endif %}
77112
</ul>
78113
</nav>
79114
</div>

_others/about.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: About others
3+
author: Tao He
4+
date: 2022-02-04
5+
category: Jekyll
6+
layout: post
7+
---
8+
9+
This is an about page for "others" in the collections.

0 commit comments

Comments
 (0)