Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #1999
  • Loading branch information
ralsina committed Sep 2, 2015
1 parent 50bf2cb commit fe4663c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* New support for online CSS and JS minifying services (Issue #1999)
* Make <base> tag optional with USE_BASE_TAG flag (Issue #1985)
* Render author pages (Issue #1972)
* Atom feeds for tag lists (Issue #1686)
Expand Down
5 changes: 5 additions & 0 deletions docs/manual.txt
Expand Up @@ -1350,6 +1350,11 @@ optipng
jpegoptim
Compress JPEG files using `jpegoptim <http://www.kokkonen.net/tjko/projects.html>`_

cssminify
Minify CSS using http://cssminifier.com/ (requires internet access)

jsminify
Minify JS using http://javascript-minifier.com/ (requires internet access)

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

Expand Down
28 changes: 28 additions & 0 deletions nikola/filters.py
Expand Up @@ -39,7 +39,9 @@
import typogrify.filters as typo
except ImportError:
typo = None # NOQA
import requests

from utils import LOGGER

def apply_to_binary_file(f):
"""Apply a filter to a binary file.
Expand Down Expand Up @@ -274,3 +276,29 @@ def php_template_injection(data):
return phpdata
else:
return data


@apply_to_text_file
def cssminify(data):
"""Minify CSS using http://cssminifier.com/"""
try:
url = 'http://cssminifier.com/raw'
_data = {'input': data}
response = requests.post(url, data=_data)
return response.text
except Exception as exc:
LOGGER.error("can't use cssminifier.com: {}", exc)
return data


@apply_to_text_file
def jsminify(data):
"""Minify JS using http://javascript-minifier.com/"""
try:
url = 'http://javascript-minifier.com/raw'
_data = {'input': data}
response = requests.post(url, data=_data)
return response.text
except Exception as exc:
LOGGER.error("can't use javascript-minifier.com: {}", exc)
return data

0 comments on commit fe4663c

Please sign in to comment.