Skip to content
Permalink
Browse files
New xmlminify filter (Atom, sitemaps)
  • Loading branch information
da2x committed Sep 29, 2015
1 parent a58c60b commit 4b1a2d0d1b8dee4eaf178866d767edb3ea2652a4
Showing with 10 additions and 0 deletions.
  1. +1 −0 CHANGES.txt
  2. +3 −0 docs/manual.txt
  3. +6 −0 nikola/filters.py
@@ -5,6 +5,7 @@ Features
--------

* New ```jsonmnify``` filter for minifying JSON files.
* New ```xmlmnify``` filter for minifying XML files.
* New option ``FEED_PREVIEWIMAGE`` includes the ``post.meta.previewimage``
image in Atom and RSS feeds. (Issue #2095)

@@ -1384,6 +1384,9 @@ jsminify
jsonminify
Minify JSON files (strip whitespace and use minimal separators).

xmlminify
Minify XML files. Suitable for Nikola’s sitemaps and Atom feeds.

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

.. code:: restructuredtext
@@ -315,6 +315,12 @@ def jsonminify(data):
data = json.dumps(json.loads(data), indent=None, separators=(',', ':'))
return data

@apply_to_binary_file
def xmlminify(data):
"""Minify XML files (strip whitespace and use minimal separators)."""
parser = lxml.etree.XMLParser(remove_blank_text=True)
newdata = lxml.etree.XML(data, parser=parser)
return lxml.etree.tostring(newdata, encoding='utf-8', method='xml', xml_declaration=True)

def _normalize_html(data):
"""Pass HTML through LXML to clean it up, if possible."""

0 comments on commit 4b1a2d0

Please sign in to comment.