Skip to content

Commit

Permalink
Checksum PHP source files to ensure they regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed Jul 30, 2014
1 parent 274012c commit c5f441b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nikola/filters.py
Expand Up @@ -171,7 +171,7 @@ def typogrify(data):
@apply_to_text_file
def php_template_injection(data):
import re
template = re.search('<\!-- __NIKOLA_PHP_TEMPLATE_INJECTION\:(.*)__ -->', data)
template = re.search('<\!-- __NIKOLA_PHP_TEMPLATE_INJECTION source\:(.*) csum\:(.*)__ -->', data)
if template:
source = template.group(1)
with codecs.open(source, "r", "utf8") as in_file:
Expand Down
5 changes: 4 additions & 1 deletion nikola/plugins/compile/php.py
Expand Up @@ -33,6 +33,7 @@

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata
from hashlib import md5


class CompilePhp(PageCompiler):
Expand All @@ -43,7 +44,9 @@ class CompilePhp(PageCompiler):
def compile_html(self, source, dest, is_two_file=True):
makedirs(os.path.dirname(dest))
with codecs.open(dest, "w+", "utf8") as out_file:
out_file.write('<!-- __NIKOLA_PHP_TEMPLATE_INJECTION:{0}__ -->'.format(source))
with open(source, "rb") as in_file:
hash = md5(in_file.read()).hexdigest()
out_file.write('<!-- __NIKOLA_PHP_TEMPLATE_INJECTION source:{0} csum:{1}__ -->'.format(source, hash))
return True

def create_post(self, path, **kw):
Expand Down

0 comments on commit c5f441b

Please sign in to comment.