Skip to content

Commit

Permalink
Enable customized order for collections (resolves sighingnow#123).
Browse files Browse the repository at this point in the history
  • Loading branch information
sighingnow committed Jun 30, 2024
1 parent a17eec0 commit b6353bf
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 25 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,24 @@ collections:
output: true
sort_by: date
permalink: /:collection/:year-:month-:day-:title:output_ext
others:
output: true
sort_by: date
permalink: /:collection/:year-:month-:day-:title:output_ext
```

An optional `ordered_collections` key can be added to `_config.yaml` to control the order of collections in the sidebar:

```yaml
ordered_collections:
- posts
- pages
- others
```

If not specified, the order of collections would be decided by Jekyll. Note that the key `posts` is a special collection
that indicates the `_posts` pages of Jekyll.

## Extra StyleSheet or Javascript elements

You can add extra CSS or JavaScript references using configuration collections:
Expand Down
8 changes: 8 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ collections:
pages:
output: true
permalink: /:collection/:path/
others:
output: true
permalink: /:collection/:path/

ordered_collections:
- posts
- pages
- others

page_width: 800px

Expand Down
85 changes: 60 additions & 25 deletions _includes/toc-date.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,72 @@

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

{% for collection in site.collections %}
<!-- <p>{{ collection.label }}</p> -->
{% if collection.output %}
{% if collection.label == "posts" %}
{% assign reversed_posts = site[collection.label] | reverse %}
{% else %}
{% assign reversed_posts = site[collection.label] %}
{% endif %}

{% for post in reversed_posts %}
{% if page.url == post.url %}
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
{% if site.ordered_collections %}
{% for label in site.ordered_collections %}
{% assign collection = site.collections | where: "label", label | first %}
<!-- <p>{{ collection.label }}</p> -->
{% if collection.output %}
{% if collection.label == "posts" %}
{% assign reversed_posts = site[collection.label] | reverse %}
{% else %}
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
{% assign reversed_posts = site[collection.label] %}
{% endif %}
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
{{ post.title | escape }}
</a>
{% if site.toc.enabled %}
{% if page.url == post.url %}
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}

{% for post in reversed_posts %}
{% if page.url == post.url %}
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
{% else %}
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
{% endif %}
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
{{ post.title | escape }}
</a>
{% if site.toc.enabled %}
{% if page.url == post.url %}
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}
{% endif %}
{% endif %}
</li>
{% endfor %}

{% if reversed_posts.size > 0 %}
<li class="divider"></li>
{% endif %}
{% endif %}
{% endfor %}
{% else %}
{% for collection in site.collections %}
<!-- <p>{{ collection.label }}</p> -->
{% if collection.output %}
{% if collection.label == "posts" %}
{% assign reversed_posts = site[collection.label] | reverse %}
{% else %}
{% assign reversed_posts = site[collection.label] %}
{% endif %}

{% for post in reversed_posts %}
{% if page.url == post.url %}
<li class="chapter active" data-level="1.2" data-path="{{site.baseurl}}{{post.url}}">
{% else %}
<li class="chapter" data-level="1.1" data-path="{{site.baseurl}}{{post.url}}">
{% endif %}
</li>
{% endfor %}
<a href="{{site.baseurl}}{{post.url}}" onclick="pageScrollToTop(this)">
{{ post.title | escape }}
</a>
{% if site.toc.enabled %}
{% if page.url == post.url %}
{% include toc.html html=content h_min=site.toc.h_min h_max=site.toc.h_max %}
{% endif %}
{% endif %}
</li>
{% endfor %}

{% if reversed_posts.size > 0 %}
<li class="divider"></li>
{% if reversed_posts.size > 0 %}
<li class="divider"></li>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</nav>
</div>
9 changes: 9 additions & 0 deletions _others/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: About others
author: Tao He
date: 2022-02-04
category: Jekyll
layout: post
---

This is an about page for "others" in the collections.

0 comments on commit b6353bf

Please sign in to comment.