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

Generate posts feed by custom sorting method #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ feed:
posts_limit: 20
```

### Posts sort

By default, posts will be sorted by `date` in the feed. Simply define a new sorting method in your config:

```yml
feed:
posts_sort: last_modified_at
```

## Collections

Jekyll Feed can generate feeds for collections other than the Posts collection. This works best for chronological collections (e.g., collections with dates in the filenames). Simply define which collections you'd like feeds for in your config:
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
{% unless site.show_drafts %}
{% assign posts = posts | where_exp: "post", "post.draft != true" %}
{% endunless %}
{% assign posts = posts | sort: "date" | reverse %}
{% assign posts_sort = site.feed.posts_sort | default: "date" %}
{% assign posts = posts | sort: posts_sort | reverse %}
{% assign posts_limit = site.feed.posts_limit | default: 10 %}
{% for post in posts limit: posts_limit %}
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
Expand Down