Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
30 lines (22 sloc) 1.03 KB
"""Html min extension for minifying HTML in Grow sites."""
import htmlmin
from grow import extensions
from grow.extensions import hooks
from grow.documents import document
class HtmlMinPostRenderHook(hooks.PostRenderHook):
"""Handle the post-render hook."""
def should_trigger(self, previous_result, *_args, **_kwargs):
"""Determine if the hook should trigger."""
return self.extension.config.get('enabled', True)
def trigger(self, previous_result, doc, raw_content, *_args, **_kwargs):
"""Execute post-render modification."""
if not isinstance(doc, document.Document) or not doc.view.endswith('.html'):
return previous_result
content = previous_result if previous_result else raw_content
return htmlmin.minify(content, **self.extension.config.get('options', {}))
class HtmlMinExtension(extensions.BaseExtension):
"""Example Extension."""
@property
def available_hooks(self):
"""Returns the available hook classes."""
return [HtmlMinPostRenderHook]