Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort collections #272

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ This layout displays all documents grouped by a specific collection. It accommod
```yaml
collection: # collection name
entries_layout: # list (default), grid
show_excerpts: # true (default), false
sort_by: # date (default) title
sort_order: # forward (default), reverse
```

To create a page showing all documents in the `recipes` collection you'd create `recipes.md` in the root of your project and add this front matter:
Expand All @@ -648,7 +651,7 @@ permalink: /recipes/
collection: recipes
```

By default, documents are shown in a list view. To change to a grid view add `entries_layout: grid` to the page's front matter.
By default, documents are shown in a list view. To change to a grid view add `entries_layout: grid` to the page's front matter. If you want to sort the collection by title add `sort_by: title`. If you want reverse sorting, add `sort_order: reverse`. If you are simply looking for list that shows recipe titles (no excerpts), add `show_excerpts: false`.

### `layout: category`

Expand Down
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ feed:
# Search
search_full_content: false # can have performance implications for large sites

# Taxonomoy pages
# Taxonomy pages
# category_archive_path: "/categories/#"
# tag_archive_path: "/tags/#"

Expand Down
18 changes: 17 additions & 1 deletion _includes/documents-collection.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{%- for entry in site[include.collection] -%}
{% assign entries = site[include.collection] %}

{% if include.sort_by == 'title' %}
{% if include.sort_order == 'reverse' %}
{% assign entries = entries | sort: 'title' | reverse %}
{% else %}
{% assign entries = entries | sort: 'title' %}
{% endif %}
{% elsif include.sort_by == 'date' %}
{% if include.sort_order == 'reverse' %}
{% assign entries = entries | sort: 'date' | reverse %}
{% else %}
{% assign entries = entries | sort: 'date' %}
{% endif %}
{% endif %}

{%- for entry in entries -%}
{% include entry.html %}
{%- endfor -%}
2 changes: 1 addition & 1 deletion _layouts/collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
{{ content }}

<div class="entries-{{ page.entries_layout | default: 'list' }}">
{% include documents-collection.html collection=page.collection %}
{% include documents-collection.html collection=page.collection sort_by=page.sort_by sort_order=page.sort_order %}
</div>
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ paginate_path: /page:num/
# Search
search_full_content: false

# Taxonomoy pages
# Taxonomy pages
category_archive_path: "/categories/#"
tag_archive_path: "/tags/#"

Expand Down
2 changes: 1 addition & 1 deletion example/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ paginate_path: /page:num/
# Search
search_full_content: false

# Taxonomoy pages
# Taxonomy pages
category_archive_path: "/categories/#"
tag_archive_path: "/tags/#"

Expand Down