@@ -73,8 +73,7 @@ class encryptContentPlugin(BasePlugin):
7373 ('experimental' , config_options .Type (bool , default = False )),
7474 # legacy features, doesn't exist anymore
7575 ('disable_cookie_protection' , config_options .Type (bool , default = False )),
76- ('decrypt_search' , config_options .Type (bool , default = False )),
77-
76+ ('decrypt_search' , config_options .Type (bool , default = False ))
7877 )
7978
8079 def __hash_md5__ (self , text ):
@@ -100,7 +99,7 @@ def __encrypt_text_aes__(self, text, password):
10099 PADDING_CHAR
101100 )
102101
103- def __encrypt_content__ (self , content ):
102+ def __encrypt_content__ (self , content , base_path ):
104103 """ Replaces page or article content with decrypt form. """
105104 ciphertext_bundle = self .__encrypt_text_aes__ (content , str (self .config ['password' ]))
106105 decrypt_form = Template (DECRYPT_FORM_TPL ).render ({
@@ -114,6 +113,7 @@ def __encrypt_content__(self, content):
114113 # otherwise the output string will be wrapped with b''
115114 'ciphertext_bundle' : b';' .join (ciphertext_bundle ).decode ('ascii' ),
116115 'js_libraries' : JS_LIBRARIES ,
116+ 'base_path' : base_path
117117 })
118118 return decrypt_form
119119
@@ -130,7 +130,7 @@ def __generate_decrypt_js__(self):
130130 'default_expire_dalay' : int (self .config ['default_expire_dalay' ]),
131131 'encrypted_something' : self .config ['encrypted_something' ],
132132 'reload_scripts' : self .config ['reload_scripts' ],
133- 'experimental' : self .config ['experimental' ],
133+ 'experimental' : self .config ['experimental' ]
134134 })
135135 return decrypt_js
136136
@@ -233,7 +233,7 @@ def _add_entry_from_context(self, page):
233233 config ['extra_javascript' ].append ('search/main.js' )
234234 except Exception as exp :
235235 logger .exception (exp )
236-
236+
237237 def on_page_markdown (self , markdown , page , config , ** kwargs ):
238238 """
239239 The page_markdown event is called after the page's markdown is loaded from file and
@@ -275,10 +275,12 @@ def on_page_content(self, html, page, config, **kwargs):
275275 if self .config ['tag_encrypted_page' ]:
276276 # Set attribute on page to identify encrypted page on template rendering
277277 setattr (page , 'encrypted' , True )
278+ # Create relative path in case of subdir in site_url
279+ base_path = page .abs_url .replace (page .url ,'' )
278280 # Set password attributes on page for other mkdocs events
279281 setattr (page , 'password' , str (self .config ['password' ]))
280282 # Keep encrypted html as temporary variable on page cause we need clear html for search plugin
281- setattr (page , 'html_encrypted' , self .__encrypt_content__ (html ))
283+ setattr (page , 'html_encrypted' , self .__encrypt_content__ (html , base_path ))
282284 return html
283285
284286 def on_page_context (self , context , page , config , ** kwargs ):
@@ -360,4 +362,4 @@ def on_post_build(self, config, **kwargs):
360362 decrypt_js_path = Path (config .data ["site_dir" ] + '/assets/javascripts/decrypt-contents.js' )
361363 with open (decrypt_js_path , "w" ) as f :
362364 f .write (self .__generate_decrypt_js__ ())
363- config [ 'extra_javascript' ]. append ( "/assets/javascripts/decrypt-contents.js" )
365+
0 commit comments