28
28
import sys
29
29
30
30
from nikola .plugin_categories import PageCompiler
31
- from nikola .utils import makedirs , write_metadata
31
+ from nikola .utils import makedirs , write_metadata , LocaleBorg
32
32
from nikola .utils import get_logger , STDERR_HANDLER
33
33
34
34
from . import default_filters , php , plugin_interface , shortcodes
@@ -111,6 +111,7 @@ class CompileWordpress(PageCompiler):
111
111
112
112
name = "wordpress"
113
113
demote_headers = True
114
+ use_dep_files = False
114
115
site = None
115
116
116
117
def __init__ (self ):
@@ -193,8 +194,14 @@ def compile_to_string(self, source_data, name=None, additional_data=None):
193
194
context = Context (hash (source_data ), name = name , additional_data = additional_data )
194
195
return self .__formatData (source_data , context )
195
196
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 )
198
205
if os .path .isfile (dep_path ):
199
206
with io .open (dep_path , 'rb' ) as file :
200
207
result = json .loads (file .read ().decode ('utf-8' ))
@@ -203,21 +210,20 @@ def _read_extra_deps(self, post):
203
210
return ([], [], [], [])
204
211
205
212
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 ))
221
227
222
228
def _read_similar_file (self , source , suffix ):
223
229
path , filename = os .path .split (source )
@@ -247,7 +253,9 @@ def load_additional_data(self, source):
247
253
248
254
return result , dependent_files
249
255
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
251
259
makedirs (os .path .dirname (dest ))
252
260
with io .open (dest , "w+" , encoding = "utf8" ) as out_file :
253
261
# Read post
@@ -264,7 +272,14 @@ def compile_html(self, source, dest, is_two_file=False):
264
272
output = self .__formatData (data , context )
265
273
# Write result
266
274
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 )
268
283
269
284
def create_post (self , path , content = None , onefile = False , is_page = False , ** kw ):
270
285
content = kw .pop ('content' , None )
0 commit comments