2013-03-29 10:01:04 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2013-04-25 17:00:57 +00:00
|
|
|
# Hook routines for the wok static site generator.
|
|
|
|
# Note that mediacompress is a local module.
|
2013-04-24 18:25:42 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
2013-03-29 10:01:04 +00:00
|
|
|
def compress_javascript(config, output_path):
|
2013-04-24 18:25:42 +00:00
|
|
|
"""Minify JS files."""
|
2013-04-25 17:00:57 +00:00
|
|
|
try:
|
|
|
|
from mediacompress import compress_js_files
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
compress_js_files(output_path, excludes=("*.min.js",))
|
2013-03-29 10:01:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def compress_css(config, output_path):
|
2013-04-24 18:25:42 +00:00
|
|
|
"""Minify CSS files."""
|
2013-04-25 17:00:57 +00:00
|
|
|
try:
|
|
|
|
from mediacompress import compress_css_files
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
compress_css_files(output_path)
|
2013-03-29 10:01:04 +00:00
|
|
|
|
2013-04-24 18:25:42 +00:00
|
|
|
|
|
|
|
def chmod(config):
|
|
|
|
"""Set correct file permissions."""
|
|
|
|
output_dir = config["output_dir"]
|
|
|
|
for dirpath, dirnames, filenames in os.walk(output_dir):
|
|
|
|
for dirname in dirnames:
|
|
|
|
os.chmod(os.path.join(dirpath, dirname), 0755)
|
|
|
|
for filename in filenames:
|
|
|
|
os.chmod(os.path.join(dirpath, filename), 0644)
|
|
|
|
|
|
|
|
|
2013-03-29 10:01:04 +00:00
|
|
|
hooks = {
|
|
|
|
'site.output.post': [compress_javascript, compress_css],
|
2013-04-24 18:25:42 +00:00
|
|
|
'site.done': [chmod],
|
2013-03-29 10:01:04 +00:00
|
|
|
}
|