Skip to content

Commit

Permalink
Per-post/page filters (Issue #914)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Jun 13, 2015
1 parent 7ca4bf4 commit a5fd510
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in v7.5.1
Features
--------

* Apply per-post filters via metadata (Issue #914)
* Suggest misspelled commands (Issue #1807)
* New implementation of the ``nikola auto`` command.
* ``requests`` is now required for all Nikola sites
Expand Down
20 changes: 20 additions & 0 deletions docs/manual.txt
Expand Up @@ -503,6 +503,9 @@ to your configuration::
Like tags, except each post can have only one, and they usually have
more descriptive names.

filters
See the `Post Processing Filters`_ section.

hidetitle
Set "True" if you do not want to see the **page** title as a
heading of the output html file (does not work for posts).
Expand Down Expand Up @@ -1364,6 +1367,18 @@ html_tidy_wrap_attr
html_tidy_mini
Minify HTML 5 into smaller documents with `tidy5 <http://www.html-tidy.org/>`_

html5lib_minify
Minify HTML5 using html5lib_minify

html5lib_xmllike
Format using html5lib

typogrify
Use a `tipogrify filter <http://static.mintchaos.com/projects/typogrify/>`__

typogrify_sans_widont
Same as typogrify without the widont filter

minify_lines
**THIS FILTER HAS BEEN TURNED INTO A NOOP** and currently does nothing.

Expand All @@ -1382,6 +1397,11 @@ jpegoptim
typogrify
Improve typography using `typogrify <https://github.com/mintchaos/typogrify>`_

You can apply filters to specific posts or pages by using the ``filters`` metadata field::

.. filters:: filters.html_tidy_nowrap, "sed s/foo/bar"



Optimizing Your Website
-----------------------
Expand Down
18 changes: 16 additions & 2 deletions nikola/plugins/task/posts.py
Expand Up @@ -25,9 +25,10 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from copy import copy
import os

from nikola.plugin_categories import Task
from nikola import utils
from nikola import filters, utils


def update_deps(post, lang, task):
Expand Down Expand Up @@ -91,7 +92,20 @@ def tl_ch():
] + post.fragment_deps_uptodate(lang),
'task_dep': ['render_posts:timeline_changes']
}
yield task

# Apply filters specified in the metadata
ff = [x.strip() for x in post.meta('filters', lang).split(',')]
flist = []
for i, f in enumerate(ff):
if not f:
continue
if f.startswith('filters.'): # A function from the filters module
f = f[8:]
if f in filters.__dict__:
flist.append(filters.__dict__[f])
else:
flist.append(f)
yield utils.apply_filters(task, {os.path.splitext(dest): flist})

def dependence_on_timeline(self, post, lang):
if "####MAGIC####TIMELINE" not in post.fragment_deps(lang):
Expand Down

0 comments on commit a5fd510

Please sign in to comment.