Skip to content
Permalink
Browse files
Add category to post list (via #1889)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 25, 2015
1 parent 2fb49d6 commit 32655b7fec9c81f66b974de4972e748ca3255557
Showing with 15 additions and 1 deletion.
  1. +1 −0 CHANGES.txt
  2. +3 −0 docs/manual.txt
  3. +11 −1 nikola/plugins/compile/rest/post_list.py
@@ -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
@@ -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...]
@@ -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.
@@ -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.
@@ -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,
@@ -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)
@@ -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

0 comments on commit 32655b7

Please sign in to comment.