Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New xmlminify filter (Atom, sitemaps)
  • Loading branch information
da2x committed Sep 29, 2015
1 parent a58c60b commit 4b1a2d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions docs/manual.txt
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions nikola/filters.py
Expand Up @@ -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."""
Expand Down

0 comments on commit 4b1a2d0

Please sign in to comment.