Skip to content

Commit e531b87

Browse files
committed
fix crash when search plugin wasn't enabled
1 parent 0cae480 commit e531b87

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

encryptcontent/plugin.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,24 +407,25 @@ def on_post_page(self, output_content, page, config, **kwargs):
407407

408408
if hasattr(page, 'encrypted'):
409409
#encrypt or exclude encrypted pages from search_index.json
410-
search_entries = config['plugins']['search'].search_index._entries
411-
for entry in search_entries.copy(): #iterate through all entries of search_index
412-
location = page.url.lstrip('/')
413-
if entry['location'] == location or entry['location'].startswith(location+"#"): #find the ones located at encrypted pages
414-
if self.config['search_index'] == 'encrypted':
415-
search_entries.remove(entry)
416-
elif self.config['search_index'] == 'dynamically' and page.password is not None:
417-
#encrypt text/title/location(anchor only)
418-
text = entry['text']
419-
title = entry['title']
420-
toc_anchor = entry['location'].replace(location, '')
421-
code = self.__encrypt_text_aes__(text, page.password)
422-
entry['text'] = b';'.join(code).decode('ascii')
423-
code = self.__encrypt_text_aes__(title, page.password)
424-
entry['title'] = b';'.join(code).decode('ascii')
425-
code = self.__encrypt_text_aes__(toc_anchor, page.password)
426-
entry['location'] = location + ';' + b';'.join(code).decode('ascii')
427-
config['plugins']['search'].search_index._entries = search_entries
410+
if 'search' in config['plugins']:
411+
search_entries = config['plugins']['search'].search_index._entries
412+
for entry in search_entries.copy(): #iterate through all entries of search_index
413+
location = page.url.lstrip('/')
414+
if entry['location'] == location or entry['location'].startswith(location+"#"): #find the ones located at encrypted pages
415+
if self.config['search_index'] == 'encrypted':
416+
search_entries.remove(entry)
417+
elif self.config['search_index'] == 'dynamically' and page.password is not None:
418+
#encrypt text/title/location(anchor only)
419+
text = entry['text']
420+
title = entry['title']
421+
toc_anchor = entry['location'].replace(location, '')
422+
code = self.__encrypt_text_aes__(text, page.password)
423+
entry['text'] = b';'.join(code).decode('ascii')
424+
code = self.__encrypt_text_aes__(title, page.password)
425+
entry['title'] = b';'.join(code).decode('ascii')
426+
code = self.__encrypt_text_aes__(toc_anchor, page.password)
427+
entry['location'] = location + ';' + b';'.join(code).decode('ascii')
428+
config['plugins']['search'].search_index._entries = search_entries
428429

429430
return output_content
430431

0 commit comments

Comments
 (0)