Skip to content

Commit 32655b7

Browse files
committedJul 25, 2015
Add category to post list (via #1889)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 2fb49d6 commit 32655b7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

Diff for: ‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ New in master
44
Features
55
--------
66

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

910
Bugfixes

Diff for: ‎docs/manual.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,10 @@ The following options are recognized:
17371737

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

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

17431746
* ``slugs`` : string [, string...]

Diff for: ‎nikola/plugins/compile/rest/post_list.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PostList(Directive):
5454
Post List
5555
=========
5656
:Directive Arguments: None.
57-
:Directive Options: lang, start, stop, reverse, sort, tags, template, id
57+
:Directive Options: lang, start, stop, reverse, sort, tags, categories, slugs, all, template, id
5858
:Directive Content: None.
5959
6060
Provides a reStructuredText directive to create a list of posts.
@@ -87,6 +87,10 @@ class PostList(Directive):
8787
Filter posts to show only posts having at least one of the ``tags``.
8888
Defaults to None.
8989
90+
``categories`` : string [, string...]
91+
Filter posts to show only posts having one of the ``categories``.
92+
Defaults to None.
93+
9094
``slugs`` : string [, string...]
9195
Filter posts to show only posts having at least one of the ``slugs``.
9296
Defaults to None.
@@ -113,6 +117,7 @@ class PostList(Directive):
113117
'reverse': directives.flag,
114118
'sort': directives.unchanged,
115119
'tags': directives.unchanged,
120+
'categories': directives.unchanged,
116121
'slugs': directives.unchanged,
117122
'all': directives.flag,
118123
'lang': directives.unchanged,
@@ -126,6 +131,8 @@ def run(self):
126131
reverse = self.options.get('reverse', False)
127132
tags = self.options.get('tags')
128133
tags = [t.strip().lower() for t in tags.split(',')] if tags else []
134+
categories = self.options.get('categories')
135+
categories = [c.strip().lower() for c in categories.split(',')] if categories else []
129136
slugs = self.options.get('slugs')
130137
slugs = [s.strip() for s in slugs.split(',')] if slugs else []
131138
show_all = self.options.get('all', False)
@@ -145,6 +152,9 @@ def run(self):
145152
else:
146153
timeline = [p for p in self.site.timeline if p.use_in_feeds]
147154

155+
if categories:
156+
timeline = [p for p in timeline if p.meta('category', lang=lang).lower() in categories]
157+
148158
for post in timeline:
149159
if tags:
150160
cont = True

0 commit comments

Comments
 (0)
Please sign in to comment.