dosage/doc/web/hooks/__hooks__.py

41 lines
1 KiB
Python
Raw Normal View History

2013-03-29 10:01:04 +00:00
# -*- coding: iso-8859-1 -*-
# 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."""
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."""
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
}