Skip to content
Permalink
Browse files
Fix #2409 -- support sections in post lists
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 27, 2016
1 parent 90f204e commit 59a3c4c86e9460621f78626ba29f8f2ae044db70
Showing with 21 additions and 5 deletions.
  1. +2 −0 CHANGES.txt
  2. +4 −0 docs/manual.txt
  3. +15 −5 nikola/plugins/compile/rest/post_list.py
@@ -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
@@ -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.
@@ -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.
@@ -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.
@@ -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,
@@ -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')
@@ -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:
@@ -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
@@ -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

0 comments on commit 59a3c4c

Please sign in to comment.