@@ -626,30 +626,36 @@ def on_page_markdown(self, markdown, page, config, **kwargs):
626626 del page .meta ['encryption_info_message' ]
627627
628628 if encryptcontent .get ('password' ):
629- if encryptcontent ['password' ] not in self .setup ['password_keys' ]:
629+ index = encryptcontent ['password' ]
630+ if index not in self .setup ['password_keys' ]:
630631 new_entry = {}
631632 self .keystore_id += 1
632633 new_entry ['id' ] = quote (self .config ['remember_suffix' ] + str (self .keystore_id ), safe = '~()*!\' ' )
633634 new_entry ['key' ] = get_random_bytes (32 )
634- self .__add_to_keystore__ ((KS_PASSWORD ,password ), new_entry ['key' ], new_entry ['id' ], encryptcontent [ 'password' ] )
635- self .setup ['password_keys' ][encryptcontent [ 'password' ] ] = new_entry
635+ self .__add_to_keystore__ ((KS_PASSWORD ,index ), new_entry ['key' ], new_entry ['id' ], index )
636+ self .setup ['password_keys' ][index ] = new_entry
636637 encryptcontent ['type' ] = 'password'
637- encryptcontent ['key' ] = self .setup ['password_keys' ][encryptcontent ['password' ]]['key' ]
638+ encryptcontent ['key' ] = self .setup ['password_keys' ][index ]['key' ]
639+ encryptcontent ['id' ] = self .setup ['password_keys' ][index ]['id' ]
638640 setattr (page , 'encryptcontent' , encryptcontent )
639641 elif encryptcontent .get ('level' ):
642+ index = encryptcontent ['level' ]
640643 encryptcontent ['type' ] = 'level'
641- encryptcontent ['key' ] = self .setup ['level_keys' ][encryptcontent ['level' ]]['key' ]
644+ encryptcontent ['key' ] = self .setup ['level_keys' ][index ]['key' ]
645+ encryptcontent ['id' ] = self .setup ['level_keys' ][index ]['id' ]
642646 setattr (page , 'encryptcontent' , encryptcontent )
643647 elif encryptcontent .get ('obfuscate' ):
644- if encryptcontent ['obfuscate' ] not in self .setup ['obfuscate_keys' ]:
648+ index = encryptcontent ['obfuscate' ]
649+ if index not in self .setup ['obfuscate_keys' ]:
645650 new_entry = {}
646651 self .keystore_id += 1
647652 new_entry ['id' ] = quote (self .config ['remember_suffix' ] + str (self .keystore_id ), safe = '~()*!\' ' )
648653 new_entry ['key' ] = get_random_bytes (32 )
649- self .__add_to_keystore__ ((KS_OBFUSCATE ,encryptcontent [ 'obfuscate' ] ), new_entry ['key' ], new_entry ['id' ], encryptcontent [ 'obfuscate' ] )
650- self .setup ['obfuscate_keys' ][encryptcontent [ 'obfuscate' ] ] = new_entry
654+ self .__add_to_keystore__ ((KS_OBFUSCATE ,index ), new_entry ['key' ], new_entry ['id' ], index )
655+ self .setup ['obfuscate_keys' ][index ] = new_entry
651656 encryptcontent ['type' ] = 'obfuscate'
652- encryptcontent ['key' ] = self .setup ['obfuscate_keys' ][encryptcontent ['obfuscate' ]]['key' ]
657+ encryptcontent ['key' ] = self .setup ['obfuscate_keys' ][index ]['key' ]
658+ encryptcontent ['id' ] = self .setup ['obfuscate_keys' ][index ]['id' ]
653659 setattr (page , 'encryptcontent' , encryptcontent )
654660
655661 return markdown
@@ -830,7 +836,7 @@ def on_post_page(self, output_content, page, config, **kwargs):
830836
831837 if hasattr (page , 'encryptcontent' ):
832838 location = page .url .lstrip ('/' )
833- self .setup ['locations' ][location ] = page .encryptcontent ['key' ]
839+ self .setup ['locations' ][location ] = ( page .encryptcontent ['key' ], page . encryptcontent [ 'id' ])
834840 delattr (page , 'encryptcontent' )
835841
836842 if self .config ['sign_files' ]:
@@ -891,20 +897,21 @@ def on_post_build(self, config, **kwargs):
891897 for entry in search_entries ['docs' ].copy (): #iterate through all entries of search_index
892898 for location in self .setup ['locations' ].keys ():
893899 if entry ['location' ] == location or entry ['location' ].startswith (location + "#" ): #find the ones located at encrypted pages
894- page_key = self .setup ['locations' ][location ]
900+ page_key = self .setup ['locations' ][location ][0 ]
901+ page_id = self .setup ['locations' ][location ][1 ]
895902 if self .config ['search_index' ] == 'encrypted' :
896903 search_entries ['docs' ].remove (entry )
897904 elif self .config ['search_index' ] == 'dynamically' and page_key is not None :
898- #encrypt text/title/location(anchor only)
905+ #encrypt text/title/location
899906 text = entry ['text' ]
900907 title = entry ['title' ]
901- toc_anchor = entry ['location' ].replace (location , '' )
908+ location = entry ['location' ]
909+ code = self .__encrypt_text__ (location , page_key )
910+ entry ['location' ] = page_id + ';' + ';' .join (code ) # add encryptcontent_id
902911 code = self .__encrypt_text__ (text , page_key )
903912 entry ['text' ] = ';' .join (code )
904913 code = self .__encrypt_text__ (title , page_key )
905914 entry ['title' ] = ';' .join (code )
906- code = self .__encrypt_text__ (toc_anchor , page_key )
907- entry ['location' ] = location + ';' + ';' .join (code )
908915 break
909916 self .setup ['locations' ].clear ()
910917
0 commit comments