Skip to content

Commit

Permalink
Add category to post list (via #1889)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 25, 2015
1 parent 2fb49d6 commit 32655b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Add categories filter to post list directive (via Issue #1889)
* Remove empty directories with nikola check --clean-files (Issue #1873)

Bugfixes
Expand Down
3 changes: 3 additions & 0 deletions docs/manual.txt
Expand Up @@ -1737,7 +1737,10 @@ The following options are recognized:

* ``tags`` : string [, string...]
Filter posts to show only posts having at least one of the ``tags``.
Defaults to None.

* ``categories`` : string [, string...]
Filter posts to show only posts having one of the ``categories``.
Defaults to None.

* ``slugs`` : string [, string...]
Expand Down
12 changes: 11 additions & 1 deletion nikola/plugins/compile/rest/post_list.py
Expand Up @@ -54,7 +54,7 @@ class PostList(Directive):
Post List
=========
:Directive Arguments: None.
:Directive Options: lang, start, stop, reverse, sort, tags, template, id
:Directive Options: lang, start, stop, reverse, sort, tags, categories, slugs, all, template, id
:Directive Content: None.
Provides a reStructuredText directive to create a list of posts.
Expand Down Expand Up @@ -87,6 +87,10 @@ class PostList(Directive):
Filter posts to show only posts having at least one of the ``tags``.
Defaults to None.
``categories`` : string [, string...]
Filter posts to show only posts having one of the ``categories``.
Defaults to None.
``slugs`` : string [, string...]
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.
Expand All @@ -113,6 +117,7 @@ class PostList(Directive):
'reverse': directives.flag,
'sort': directives.unchanged,
'tags': directives.unchanged,
'categories': directives.unchanged,
'slugs': directives.unchanged,
'all': directives.flag,
'lang': directives.unchanged,
Expand All @@ -126,6 +131,8 @@ def run(self):
reverse = self.options.get('reverse', False)
tags = self.options.get('tags')
tags = [t.strip().lower() for t in tags.split(',')] if tags else []
categories = self.options.get('categories')
categories = [c.strip().lower() for c in categories.split(',')] if categories else []
slugs = self.options.get('slugs')
slugs = [s.strip() for s in slugs.split(',')] if slugs else []
show_all = self.options.get('all', False)
Expand All @@ -145,6 +152,9 @@ def run(self):
else:
timeline = [p for p in self.site.timeline if p.use_in_feeds]

if categories:
timeline = [p for p in timeline if p.meta('category', lang=lang).lower() in categories]

for post in timeline:
if tags:
cont = True
Expand Down

0 comments on commit 32655b7

Please sign in to comment.