Skip to content

Commit

Permalink
Merge branch 'post-list-shortcode-redux'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Jul 30, 2016
2 parents 9fe05b2 + c434dab commit 777a992
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features
Bugfixes
--------

* Support post-list shortcode better (Issue #2408)
* Fix gallery links in base theme (Issue #2416)
* Respect ``DEPLOY_DRAFTS`` and ``DEPLOY_FUTURE`` in ``github_deploy``
(Issue #2406)
Expand Down
23 changes: 15 additions & 8 deletions docs/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2051,13 +2051,13 @@ The following options are recognized:
custom ``priority``. Defaults to None (chronological sorting).

* ``date``: string
Show posts that match date range specified by this option. Format:
Show posts that match date range specified by this option. Format:

* comma-separated clauses (AND)
* clause: attribute comparison_operator value (spaces optional)
* attribute: year, month, day, hour, month, second, weekday, isoweekday; or empty for full datetime
* comparison_operator: == != <= >= < >
* value: integer or dateutil-compatible date input
* comma-separated clauses (AND)
* clause: attribute comparison_operator value (spaces optional)
* attribute: year, month, day, hour, month, second, weekday, isoweekday; or empty for full datetime
* comparison_operator: == != <= >= < >
* value: integer or dateutil-compatible date input

* ``tags`` : string [, string...]
Filter posts to show only posts having at least one of the ``tags``.
Expand All @@ -2075,9 +2075,13 @@ The following options are recognized:
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.

* ``post_type`` (or ``type``) : string
Show only ``posts``, ``pages`` or ``all``.
Replaces ``all``. Defaults to ``posts``.

* ``all`` : flag
Shows all posts and pages in the post list.
Defaults to show only posts with set *use_in_feeds*.
(deprecated, use ``post_type`` instead)
Shows all posts and pages in the post list. Defaults to show only posts.

* ``lang`` : string
The language of post *titles* and *links*.
Expand All @@ -2102,6 +2106,9 @@ the appropriate path if this happens.
We recommend using stories with dates in the past (1970-01-01) to avoid
dependency issues.

If you are using this as a shortcode, flags (``reverse``, ``all``) are meant to be used
with a ``True`` argument, eg. ``all=True``.

Importing your WordPress site into Nikola
-----------------------------------------

Expand Down
48 changes: 31 additions & 17 deletions nikola/plugins/compile/rest/post_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ class PostList(Directive):
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.
``post_type`` : string
``post_type`` (or ``type``) : string
Show only ``posts``, ``pages`` or ``all``.
Replaces ``all``. Defaults to ``posts``.
``all`` : flag
Shows all posts and pages in the post list.
Defaults to show only posts with set *use_in_feeds*.
(deprecated, use ``post_type`` instead)
Shows all posts and pages in the post list. Defaults to show only posts.
``lang`` : string
The language of post *titles* and *links*.
Expand All @@ -147,6 +147,7 @@ class PostList(Directive):
'sections': directives.unchanged,
'slugs': directives.unchanged,
'post_type': directives.unchanged,
'type': directives.unchanged,
'all': directives.flag,
'lang': directives.unchanged,
'template': directives.path,
Expand All @@ -160,22 +161,19 @@ def run(self):
stop = self.options.get('stop')
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 []
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')
show_all = self.options.get('all', False)
type = self.options.get('type', False)
all = self.options.get('all', False)
lang = self.options.get('lang', utils.LocaleBorg().current_lang)
template = self.options.get('template', 'post_list_directive.tmpl')
sort = self.options.get('sort')
date = self.options.get('date')

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)
output = _do_post_list(start, stop, reverse, tags, categories, sections, slugs, post_type, type,
all, lang, template, sort, state=self.state, site=self.site, date=date)
self.state.document.settings.record_dependencies.add("####MAGIC####TIMELINE")
if output:
return [nodes.raw('', output, format='html')]
Expand All @@ -184,7 +182,7 @@ def run(self):


def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=None,
sections=None, slugs=None, post_type='post', show_all=False,
sections=None, slugs=None, post_type='post', type=False, 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:
Expand All @@ -194,12 +192,27 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=No
else:
post_list_id = id or 'post_list_' + uuid.uuid4().hex

# If we get strings for start/stop, make them integers
if start is not None:
start = int(start)
if stop is not None:
stop = int(stop)

# Parse tags/categories/sections/slugs (input is strings)
tags = [t.strip().lower() for t in tags.split(',')] if tags else []
categories = [c.strip().lower() for c in categories.split(',')] if categories else []
sections = [s.strip().lower() for s in sections.split(',')] if sections else []
slugs = [s.strip() for s in slugs.split(',')] if slugs else []

filtered_timeline = []
posts = []
step = -1 if reverse is None else None

if type is not False:
post_type = type

# TODO: remove in v8
if show_all is None:
if all is not False:
timeline = [p for p in site.timeline]
elif post_type == 'page':
timeline = [p for p in site.timeline if not p.use_in_feeds]
Expand All @@ -208,7 +221,7 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=No
else: # post
timeline = [p for p in site.timeline if p.use_in_feeds]

# TODO: replaces show_all, uncomment in v8
# TODO: replaces all, uncomment in v8
# if post_type == 'page':
# timeline = [p for p in site.timeline if not p.use_in_feeds]
# elif post_type == 'all':
Expand Down Expand Up @@ -258,11 +271,12 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, categories=No
posts += [post]

if not posts:
return []
return ''

# Register template as a dependency (Issue #2391)
state.document.settings.record_dependencies.add(
site.template_system.get_template_path(template))
if state:
# Register template as a dependency (Issue #2391)
state.document.settings.record_dependencies.add(
site.template_system.get_template_path(template))

template_data = {
'lang': lang,
Expand Down

0 comments on commit 777a992

Please sign in to comment.