Skip to content

Commit

Permalink
Fix #2409 -- support sections in post lists
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 27, 2016
1 parent 90f204e commit 59a3c4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Add ``sections`` filtering in the post list directive
(Issue #2409)
* Update Bootstrap to v3.3.7

Bugfixes
Expand Down
4 changes: 4 additions & 0 deletions docs/manual.txt
Expand Up @@ -2067,6 +2067,10 @@ The following options are recognized:
Filter posts to show only posts having one of the ``categories``.
Defaults to None.

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

* ``slugs`` : string [, string...]
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.
Expand Down
20 changes: 15 additions & 5 deletions nikola/plugins/compile/rest/post_list.py
Expand Up @@ -63,7 +63,7 @@ class PostList(Directive):
Post List
=========
:Directive Arguments: None.
:Directive Options: lang, start, stop, reverse, sort, tags, categories, slugs, post_type, all, template, id
:Directive Options: lang, start, stop, reverse, sort, date, tags, categories, sections, slugs, post_type, all, template, id
:Directive Content: None.
The posts appearing in the list can be filtered by options.
Expand Down Expand Up @@ -108,6 +108,10 @@ class PostList(Directive):
Filter posts to show only posts having one of the ``categories``.
Defaults to None.
``sections`` : string [, string...]
Filter posts to show only posts having one of the ``sections``.
Defaults to None.
``slugs`` : string [, string...]
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.
Expand Down Expand Up @@ -140,6 +144,7 @@ class PostList(Directive):
'sort': directives.unchanged,
'tags': directives.unchanged,
'categories': directives.unchanged,
'sections': directives.unchanged,
'slugs': directives.unchanged,
'post_type': directives.unchanged,
'all': directives.flag,
Expand All @@ -158,6 +163,8 @@ def run(self):
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 []
sections = self.options.get('sections')
sections = [s.strip().lower() for s in sections.split(',')] if sections else []
slugs = self.options.get('slugs')
slugs = [s.strip() for s in slugs.split(',')] if slugs else []
post_type = self.options.get('post_type')
Expand All @@ -167,7 +174,7 @@ def run(self):
sort = self.options.get('sort')
date = self.options.get('date')

output = _do_post_list(start, stop, reverse, tags, categories, slugs, post_type,
output = _do_post_list(start, stop, reverse, tags, categories, sections, slugs, post_type,
show_all, lang, template, sort, state=self.state, site=self.site, date=date)
self.state.document.settings.record_dependencies.add("####MAGIC####TIMELINE")
if output:
Expand All @@ -177,9 +184,9 @@ def run(self):


def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=None,
slugs=None, post_type='post', show_all=False, lang=None,
template='post_list_directive.tmpl', sort=None, id=None,
data=None, state=None, site=None, date=None):
sections=None, slugs=None, post_type='post', show_all=False,
lang=None, template='post_list_directive.tmpl', sort=None,
id=None, data=None, state=None, site=None, date=None):
if lang is None:
lang = utils.LocaleBorg().current_lang
if site.invariant: # for testing purposes
Expand Down Expand Up @@ -212,6 +219,9 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=No
if categories:
timeline = [p for p in timeline if p.meta('category', lang=lang).lower() in categories]

if sections:
timeline = [p for p in timeline if p.section_name(lang).lower() in sections]

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

0 comments on commit 59a3c4c

Please sign in to comment.