Skip to content

Commit

Permalink
Merge pull request #3 from scholastica/sort-rss-feed
Browse files Browse the repository at this point in the history
add sort_by field
  • Loading branch information
tatums authored Feb 11, 2019
2 parents 4c11fb9 + fee41a0 commit 9ec4a40
Show file tree
Hide file tree
Showing 4 changed files with 4,096 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,22 @@ Finally, this will produce two separate RSS feeds:

Which is exactly what we need to support MailChimp's [RSS-to-Email](http://mailchimp.com/features/rss-to-email) feature!


### Ordering

You can limit and order by fields

In the _config.yml add a `sort_by` key

Example:

feed:
type: atom
limit: 0
sort_by:
field: date
direction: desc


### Technical details
To accomplish this, we forked / hacked the [Hexo-Generator-Category-Feed](https://github.com/wmeints/hexo-generator-feed-per-category) plugin. For more information, including a diff showing exactly what we changed, see https://github.com/scholastica/hexo-generator-feed-per-category/commit/586a0a9e422b2ebdd5c1678535a14b326a87a3dd.
5 changes: 5 additions & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ module.exports = function(locals) {
posts = posts.limit(config.feed.limit);
}

if(config.feed.sort_by) {
var direction = config.feed.sort_by.direction == 'asc' ? 1 : -1
posts = posts.sort(config.feed.sort_by.field, direction)
}

var url = config.url;
if (url[url.length - 1] !== '/') url += '/';

Expand Down
Loading

0 comments on commit 9ec4a40

Please sign in to comment.