Skip to content

Commit

Permalink
Merge branch 'master' of github.com:getnikola/nikola
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Sep 12, 2013
2 parents b7e9dfa + 16eab17 commit f476e7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
New in Master
=============

Features
--------

* Support for external gzip commands (Issue #351)

Bugfixes
--------

Expand All @@ -24,6 +29,7 @@ Bugfixes

* Remove decoding errors if files are not proper UTF-8 (Issue #691)
* Stop ignoring *.JPG and *.PNG by galleries (Issue #690)
>>>>>>> e0058dab40bcd1d189fba06d1578627716784470

New in 6.0.0
============
Expand Down
3 changes: 3 additions & 0 deletions nikola/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ COMPILERS = ${COMPILERS}
# GZIP_FILES = False
# File extensions that will be compressed
# GZIP_EXTENSIONS = ('.txt', '.htm', '.html', '.css', '.js', '.json')
# Use an external gzip command? None means no.
# Example: GZIP_COMMAND = "pigz -k {filename}"
# GZIP_COMMAND = None

# #############################################################################
# Image Gallery Options
Expand Down
1 change: 1 addition & 0 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def __init__(self, **config):
'FILES_FOLDERS': {'files': ''},
'FILTERS': {},
'GALLERY_PATH': 'galleries',
'GZIP_COMMAND': None,
'GZIP_FILES': False,
'GZIP_EXTENSIONS': ('.txt', '.htm', '.html', '.css', '.js', '.json'),
'HIDE_SOURCELINK': False,
Expand Down
15 changes: 10 additions & 5 deletions nikola/plugins/task/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import gzip
import os
import shlex
import subprocess

from nikola.plugin_categories import TaskMultiplier

Expand Down Expand Up @@ -61,13 +63,16 @@ def process(self, task, prefix):
gzipped = target + '.gz'
gzip_task['file_dep'].append(target)
gzip_task['targets'].append(gzipped)
gzip_task['actions'].append((create_gzipped_copy, (target, gzipped)))
gzip_task['actions'].append((create_gzipped_copy, (target, gzipped, self.site.config['GZIP_COMMAND'])))
if not flag:
return []
return [gzip_task]


def create_gzipped_copy(in_path, out_path):
with gzip.GzipFile(out_path, 'wb+') as outf:
with open(in_path, 'rb') as inf:
outf.write(inf.read())
def create_gzipped_copy(in_path, out_path, command=None):
if command:
subprocess.check_call(shlex.split(command.format(filename=in_path)))
else:
with gzip.GzipFile(out_path, 'wb+') as outf:
with open(in_path, 'rb') as inf:
outf.write(inf.read())

0 comments on commit f476e7b

Please sign in to comment.