aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2021-02-22 17:34:20 -0500
committerBryan Brattlof <hello@bryanbrattlof.com>2021-02-22 17:34:20 -0500
commita51ff052537b0f2e5b8c06dc2098bab8edc5da7d (patch)
tree6dc881e7c64f981afbcd7c99991ec469e6732a49
parentdd82df5572813de5c9ace93fe3fcb358df598e3f (diff)
downloadpelican-htmlmin-a51ff052537b0f2e5b8c06dc2098bab8edc5da7d.tar.gz
pelican-htmlmin-a51ff052537b0f2e5b8c06dc2098bab8edc5da7d.tar.bz2
white-space fixes
(what was I thinking with all these comments?)
-rw-r--r--pelican_htmlmin/minify.py36
1 files changed, 14 insertions, 22 deletions
diff --git a/pelican_htmlmin/minify.py b/pelican_htmlmin/minify.py
index 8d3d0eb..10e8a4c 100644
--- a/pelican_htmlmin/minify.py
+++ b/pelican_htmlmin/minify.py
@@ -10,35 +10,30 @@ logger = logging.getLogger(__name__)
def run(pelican):
+ """called after the website has been build to minify the html pages"""
- # should we be minifying HTML files
if pelican.settings.get(
- 'HTMLMIN_ENABLED',
- not logger.getEffectiveLevel() <= logging.DEBUG
+ 'HTMLMIN_ENABLED', logger.getEffectiveLevel() > logging.DEBUG
) is False:
logger.debug("'pelican-htmlmin' disabled")
return
options = pelican.settings.get(
- 'HTMLMIN_OPTIONS',
- {
+ 'HTMLMIN_OPTIONS', {
'remove_comments': True,
'remove_all_empty_space': True,
- 'remove_optional_attribute_quotes': False
- }
- )
+ 'remove_optional_attribute_quotes': False})
+
htmlfile = re.compile(
- pelican.settings.get('HTMLMIN_MATCH', r'.html?$')
- )
+ pelican.settings.get('HTMLMIN_MATCH', r'.html?$'))
+
pool = multiprocessing.Pool()
- # find all matching files and give to workers to minify
- for base, dirs, files in os.walk(pelican.settings['OUTPUT_PATH']):
- for f in filter(htmlfile.search, files):
- filepath = os.path.join(base, f)
+ for base, _, files in os.walk(pelican.settings['OUTPUT_PATH']):
+ for page in filter(htmlfile.search, files):
+ filepath = os.path.join(base, page)
pool.apply_async(worker, (filepath, options))
- # wait for the workers to finish
pool.close()
pool.join()
@@ -46,17 +41,14 @@ def run(pelican):
def worker(filepath, options):
"""use htmlmin to minify the given file"""
- # copy file into memory while we minify it
- with open(filepath, encoding='utf-8') as f:
- rawhtml = f.read()
+ with open(filepath, encoding='utf-8') as page:
+ rawhtml = page.read()
- # minify 'rawhtml' and save the minified
- # version back to the same location
- with open(filepath, 'w', encoding='utf-8') as f:
+ with open(filepath, 'w', encoding='utf-8') as page:
logger.debug('Minifying: %s', filepath)
try:
compressed = htmlmin.minify(rawhtml, **options)
- f.write(compressed)
+ page.write(compressed)
except Exception as e:
logger.critical('Minification failed: %s', e)