Skip to content

Commit

Permalink
Use hash value that stays identical over different invocations. (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Nov 2, 2024
1 parent ff15963 commit 4b73595
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions v7/wordpress_compiler/wordpress/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import json
import re
import sys
import hashlib

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata, LocaleBorg
Expand All @@ -36,6 +37,10 @@
_LOGGER = get_logger('compile_wordpress', STDERR_HANDLER)


def _hash(data):
return int.from_bytes(hashlib.sha256(data.encode('utf-8')).digest()[:8], byteorder='little', signed=False)


class Context(object):
id = None

Expand Down Expand Up @@ -192,13 +197,13 @@ def __formatData(self, data, context, source=None):

def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML strings."""
context = Context(hash(data), name=source_path)
context = Context(_hash(data), name=source_path)
html = self.__formatData(data, context)
return (html, []) # second part are shortcode dependencies

def compile_to_string(self, source_data, name=None, additional_data=None):
"""Old interface. Might be removed at some time."""
context = Context(hash(source_data), name=name, additional_data=additional_data)
context = Context(_hash(source_data), name=name, additional_data=additional_data)
return self.__formatData(source_data, context)

def _get_dep_filename(self, post, lang):
Expand Down Expand Up @@ -273,7 +278,7 @@ def compile(self, source, dest, is_two_file=True, post=None, lang=None):
# Read additional data
additional_data, dependent_files = self.load_additional_data(source)
# Process post
context = Context(hash(data), name=source, additional_data=additional_data)
context = Context(_hash(data), name=source, additional_data=additional_data)
for filename in dependent_files:
context.add_file_dependency(filename, 'fragment')
output = self.__formatData(data, context)
Expand Down

0 comments on commit 4b73595

Please sign in to comment.