Skip to content
Permalink
Browse files
Per-post/page filters (Issue #914)
  • Loading branch information
ralsina committed Jun 13, 2015
1 parent 7ca4bf4 commit a5fd510d289a0feb313bf7096965dec7a9f8e607
Showing with 37 additions and 2 deletions.
  1. +1 −0 CHANGES.txt
  2. +20 −0 docs/manual.txt
  3. +16 −2 nikola/plugins/task/posts.py
@@ -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
@@ -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).
@@ -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.

@@ -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
-----------------------
@@ -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):
@@ -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):

0 comments on commit a5fd510

Please sign in to comment.