Skip to content

Commit

Permalink
minifyjson filter
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed Sep 21, 2015
1 parent 47de6c4 commit 402a62e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* New ```jsonmnify``` filter for minifying JSON 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 @@ -1381,6 +1381,9 @@ cssminify
jsminify
Minify JS using http://javascript-minifier.com/ (requires internet access)

jsonminify
Minify JSON files (strips whitespace and use minimal separators).

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

.. code:: restructuredtext
Expand Down
7 changes: 7 additions & 0 deletions nikola/filters.py
Expand Up @@ -29,6 +29,7 @@
from functools import wraps
import os
import io
import json
import shutil
import subprocess
import tempfile
Expand Down Expand Up @@ -307,6 +308,12 @@ def jsminify(data):
return data


@apply_to_text_file
def jsonminify(data):
data = json.dumps(json.loads(data), indent=None, separators=(',', ':'))
return data


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

0 comments on commit 402a62e

Please sign in to comment.