Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress galleries: use hash value that stays identical over different invocations #450

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading