|
@@ -9,31 +9,36 @@ logger = logging.getLogger(__name__)
|
9
|
9
|
|
10
|
10
|
# Display command output on DEBUG and TRACE
|
11
|
11
|
SHOW_OUTPUT = logger.getEffectiveLevel() <= logging.DEBUG
|
|
12
|
+PATH_CSS = 'output/theme/css/'
|
|
13
|
+PATH_JS = 'output/theme/js/'
|
12
|
14
|
|
13
|
15
|
"""
|
14
|
16
|
Minify CSS and JS files in output path
|
15
|
|
-with uglifycss and uglifyjs.
|
|
17
|
+with css-html-js-minify.
|
16
|
18
|
"""
|
|
19
|
+
|
|
20
|
+
|
17
|
21
|
def minify(pelican):
|
18
|
22
|
"""
|
19
|
23
|
Minify CSS and JavaScript
|
20
|
24
|
:param pelican: The Pelican instance
|
21
|
25
|
"""
|
22
|
|
- for dirpath, _, filenames in os.walk(pelican.settings['OUTPUT_PATH']):
|
|
26
|
+ for dirpathcss, _, filenames in os.walk(PATH_CSS):
|
23
|
27
|
for name in filenames:
|
24
|
|
- if os.path.splitext(name)[1] in ('.css'):
|
25
|
|
- filepath = os.path.join(dirpath, name)
|
26
|
|
- logger.info('minifiy %s with uglifycss', filepath)
|
27
|
|
- debug = '--debug' if SHOW_OUTPUT else ''
|
28
|
|
- call('uglifycss {} --output {} {}'.format(debug, filepath, filepath),
|
|
28
|
+ if os.path.splitext(name)[1] in '.css':
|
|
29
|
+ filepath = os.path.join(dirpathcss, name)
|
|
30
|
+ logger.info('minifiy %s with css-html-js-minify', filepath)
|
|
31
|
+ call('css-html-js-minify {}'.format(filepath),
|
29
|
32
|
shell=True)
|
30
|
|
- elif os.path.splitext(name)[1] in ('.js'):
|
31
|
|
- filepath = os.path.join(dirpath, name)
|
32
|
|
- logger.info('minifiy %s with uglifyjs', filepath)
|
33
|
|
- verbose = '-v' if SHOW_OUTPUT else ''
|
34
|
|
- min_filepath = filepath[:-3] + '.min' + filepath[-3:]
|
35
|
|
- call("uglifyjs {} {} -o {} --mangle".format(filepath, verbose, min_filepath),
|
|
33
|
+
|
|
34
|
+ for dirpathjs, _, filenames in os.walk(PATH_JS):
|
|
35
|
+ for name in filenames:
|
|
36
|
+ if os.path.splitext(name)[1] in '.js':
|
|
37
|
+ filepath = os.path.join(dirpathjs, name)
|
|
38
|
+ logger.info('minifiy %s with css-html-js-minify', filepath)
|
|
39
|
+ call("css-html-js-minify {}".format(filepath),
|
36
|
40
|
shell=True)
|
37
|
41
|
|
|
42
|
+
|
38
|
43
|
def register():
|
39
|
44
|
signals.finalized.connect(minify)
|