Skip to content

Commit 95b7bcb

Browse files
committed
Fixing .dep filename, and adjusting to getnikola/nikola#2547.
1 parent a5d8b75 commit 95b7bcb

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

v7/wordpress_compiler/wordpress/wordpress.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import sys
2929

3030
from nikola.plugin_categories import PageCompiler
31-
from nikola.utils import makedirs, write_metadata
31+
from nikola.utils import makedirs, write_metadata, LocaleBorg
3232
from nikola.utils import get_logger, STDERR_HANDLER
3333

3434
from . import default_filters, php, plugin_interface, shortcodes
@@ -111,6 +111,7 @@ class CompileWordpress(PageCompiler):
111111

112112
name = "wordpress"
113113
demote_headers = True
114+
use_dep_files = False
114115
site = None
115116

116117
def __init__(self):
@@ -193,8 +194,14 @@ def compile_to_string(self, source_data, name=None, additional_data=None):
193194
context = Context(hash(source_data), name=name, additional_data=additional_data)
194195
return self.__formatData(source_data, context)
195196

196-
def _read_extra_deps(self, post):
197-
dep_path = post.base_path + '.dep'
197+
def _get_dep_filename(self, post, lang):
198+
return post.translated_base_path(lang) + '.dep'
199+
200+
def get_extra_targets(self, post, lang, dest):
201+
return [self._get_dep_filename(post, lang)]
202+
203+
def _read_extra_deps(self, post, lang):
204+
dep_path = self._get_dep_filename(post, lang)
198205
if os.path.isfile(dep_path):
199206
with io.open(dep_path, 'rb') as file:
200207
result = json.loads(file.read().decode('utf-8'))
@@ -203,21 +210,20 @@ def _read_extra_deps(self, post):
203210
return ([], [], [], [])
204211

205212
def register_extra_dependencies(self, post):
206-
post.add_dependency(lambda: self._read_extra_deps(post)[0], 'fragment')
207-
post.add_dependency(lambda: self._read_extra_deps(post)[1], 'page')
208-
post.add_dependency_uptodate(lambda: self._read_extra_deps(post)[2], True, 'fragment')
209-
post.add_dependency_uptodate(lambda: self._read_extra_deps(post)[3], True, 'page')
210-
211-
def _write_deps(self, context, dest):
212-
deps_path = dest + '.dep'
213-
if context.has_dependencies():
214-
data = (context.get_file_dependencies_fragment(), context.get_file_dependencies_page(),
215-
context.get_uptodate_dependencies_fragment(), context.get_uptodate_dependencies_page())
216-
with io.open(deps_path, "wb") as file:
217-
file.write(json.dumps(data).encode('utf-8'))
218-
else:
219-
if os.path.isfile(deps_path):
220-
os.unlink(deps_path)
213+
def register(lang):
214+
post.add_dependency(lambda: self._read_extra_deps(post, lang)[0], 'fragment', lang=lang)
215+
post.add_dependency(lambda: self._read_extra_deps(post, lang)[1], 'page', lang=lang)
216+
post.add_dependency_uptodate(lambda: self._read_extra_deps(post, lang)[2], True, 'fragment', lang=lang)
217+
post.add_dependency_uptodate(lambda: self._read_extra_deps(post, lang)[3], True, 'page', lang=lang)
218+
219+
for lang in self.site.config['TRANSLATIONS']:
220+
register(lang)
221+
222+
def _write_deps(self, context, deps_path):
223+
data = (context.get_file_dependencies_fragment(), context.get_file_dependencies_page(),
224+
context.get_uptodate_dependencies_fragment(), context.get_uptodate_dependencies_page())
225+
with io.open(deps_path, "w+", encoding="utf8") as file:
226+
file.write(json.dumps(data))
221227

222228
def _read_similar_file(self, source, suffix):
223229
path, filename = os.path.split(source)
@@ -247,7 +253,9 @@ def load_additional_data(self, source):
247253

248254
return result, dependent_files
249255

250-
def compile_html(self, source, dest, is_two_file=False):
256+
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
257+
if lang is None:
258+
lang = LocaleBorg().current_lang
251259
makedirs(os.path.dirname(dest))
252260
with io.open(dest, "w+", encoding="utf8") as out_file:
253261
# Read post
@@ -264,7 +272,14 @@ def compile_html(self, source, dest, is_two_file=False):
264272
output = self.__formatData(data, context)
265273
# Write result
266274
out_file.write(output)
267-
self._write_deps(context, dest)
275+
if post is None:
276+
deps_path = dest + '.dep'
277+
else:
278+
deps_path = self._get_dep_filename(post, lang)
279+
self._write_deps(context, deps_path)
280+
281+
def compile_html(self, source, dest, is_two_file=False):
282+
self.compile(source, dest, is_two_file)
268283

269284
def create_post(self, path, content=None, onefile=False, is_page=False, **kw):
270285
content = kw.pop('content', None)

0 commit comments

Comments
 (0)