unverbuggt / mkdocs-encryptcontent-plugin

A MkDocs plugin that encrypt/decrypt markdown content with AES
https://unverbuggt.github.io/mkdocs-encryptcontent-plugin/
MIT License
123 stars 15 forks source link

Getting Error: AttributeError: 'dict' object has no attribute 'remove' #46

Closed Duck5el closed 1 year ago

Duck5el commented 1 year ago

When I start my mkdocs I am getting this erromessage

docs    | INFO     -  Building documentation...
docs    | INFO     -  "highlightjs" feature is disabled in your plugin configuration.
docs    | INFO     -  "arithmatex" feature is disabled in your plugin configuration.
docs    | INFO     -  "mermaid2" feature is disabled in your plugin configuration.
docs    | INFO     -  Cleaning site directory
docs    | Traceback (most recent call last):
docs    |   File "/usr/local/bin/mkdocs", line 8, in <module>
docs    |     sys.exit(cli())
docs    |              ^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
docs    |     return self.main(*args, **kwargs)
docs    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
docs    |     rv = self.invoke(ctx)
docs    |          ^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
docs    |     return _process_result(sub_ctx.command.invoke(sub_ctx))
docs    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
docs    |     return ctx.invoke(self.callback, **ctx.params)
docs    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
docs    |     return __callback(*args, **kwargs)
docs    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/mkdocs/__main__.py", line 234, in serve_command
docs    |     serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
docs    |   File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 83, in serve
docs    |     builder(config)
docs    |   File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 76, in builder
docs    |     build(config, live_server=live_server, dirty=dirty)
docs    |   File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/build.py", line 332, in build
docs    |     config.plugins.run_event('post_build', config=config)
docs    |   File "/usr/local/lib/python3.11/site-packages/mkdocs/plugins.py", line 522, in run_event
docs    |     result = method(**kwargs)
docs    |              ^^^^^^^^^^^^^^^^
docs    |   File "/usr/local/lib/python3.11/site-packages/encryptcontent/plugin.py", line 626, in on_post_build
docs    |     search_entries.remove(entry)
docs    |     ^^^^^^^^^^^^^^^^^^^^^
docs    | AttributeError: 'dict' object has no attribute 'remove'
---
password: test
---
# Test doc

test doc
plugins:
- search: {}
- encryptcontent:
    selfhost: true
    remember_password: True
    default_expire_delay: 24

This is my Dockerfile

FROM squidfunk/mkdocs-material:9.1.6

RUN pip install --upgrade pip
RUN pip install mkdocs-encryptcontent-plugin
Duck5el commented 1 year ago

If I do this

<!-- ---
password: test
--- -->

# Test

bla

The docs build and I get these logs:

docs    | INFO     -  Building documentation...
docs    | INFO     -  "highlightjs" feature is disabled in your plugin configuration.
docs    | INFO     -  "arithmatex" feature is disabled in your plugin configuration.
docs    | INFO     -  "mermaid2" feature is disabled in your plugin configuration.
docs    | INFO     -  Cleaning site directory
docs    | INFO     -  Modified search_index.
docs    | INFO     -  Downloading cryptojs for self-hosting (if needed)...
docs    | INFO     -  Documentation built in 0.33 seconds
docs    | INFO     -  [13:01:22] Watching paths for changes: 'docs', 'mkdocs.yml'
docs    | INFO     -  [13:01:22] Serving on http://0.0.0.0:8000/
Duck5el commented 1 year ago
version: "3"
services:
  docs:
    container_name: docs
    build: .
    restart: always
    volumes:
      - ./volume:/docs
    ports:
      - 2022:8000
CoinK0in commented 1 year ago

@unverbuggt search_entries is type dict, containing the keys 'config' and 'docs'. Line 629 should be search_entries['docs'].remove(entry) to remove entry from docs list.

Thank you for the new version with many improvements.

unverbuggt commented 1 year ago

You're welcome. This really fell under my radar (need to add a test for search_index: encrypted mode). Thanks for the fix.

Duck5el commented 1 year ago

by removing the plugin search it is now working

plugins:
# - search
- encryptcontent

I guess the pip version is not updated jet.

/docs $ pip show mkdocs-encryptcontent-plugin
Name: mkdocs-encryptcontent-plugin
Version: 2.5.0
Summary: A MkDocs plugin that encrypt/decrypt markdown content with AES
Home-page: https://github.com/unverbuggt/mkdocs-encryptcontent-plugin
Author: unverbuggt
Author-email: unverbuggt@xn--rthlein-n2a.de
License: MIT
Location: /usr/local/lib/python3.11/site-packages
Requires: beautifulsoup4, mkdocs, pycryptodome, pyyaml

Now that I got it running I am facing another issue. Screenshot from 2023-04-14 08-46-06

I can't submit my password when I press CTRL+ENTER nothing happens.

I also made sure the password I typed in Is correct.

unverbuggt commented 1 year ago

Did you run pip install --upgrade mkdocs-encryptcontent-plugin? the package on pip should be up-to-date. Disabling the search plugin also circumvents the problem with version 2.5.0.

were you able to input your password in the input field? For mkdocs-material (also tested version 9.1.6) I use this configuration to set the classes:

plugins:
    - encryptcontent:
        input_class: 'md-search__form md-search__input'
        button_class: 'md-search__icon'

it looks like the input field isn't visible in your screenshot. also try adding password_button: True.

if you just press enter on an encrypted page it will save the password as "encryptcontentthat%2Fpages%2Furl%2Fescaped" in session storage. However, if you press ctrl+enter it will save as "encryptcontent". Normal pressing enter on you pages root (if it is encrypted) will also save as "encryptcontent". When you browse to another encrypted page the entries in the session storage are tried in order "encryptcontent", "encryptcontent_one%2Flevel%2Fup". If these tried passwords fail, you won't reveice an error message, only if you enter a wrong password yourself.

Best spot to debug this is to check javascript console output (F12 in most browsers) and also check the saved values to session storage (firefox: F12, Web-storage. Session storage, chrome/edge: F12, Application, Storage, Session Storage).

Duck5el commented 1 year ago

pip install --upgrade mkdocs-encryptcontent-plugin fixed the problem with the search plugin. But I am still facing the decrypt problem that the Button isn't working.

The console error says: Screenshot from 2023-04-14 10-10-52

And by adding this to my yaml:

- search
- encryptcontent:
    input_class: 'md-search__form md-search__input'
    button_class: 'md-search__icon'
    password_button: True

Everything looks normal now Screenshot from 2023-04-14 10-11-04

unverbuggt commented 1 year ago

ah, so cryptjs is missing.

this example in the documentation is probably not working as-is:

plugins:
    - encryptcontent:
        selfhost: true
        selfhost_download: false
        selfhost_dir: 'theme_overrides'

either disable selfhost: false, this way crypro-js is downloaded from external cdn.

Or enable selfhost_download: true and adjust selfhost_dir to you custom dir of the theme. You can also remove selfhost_dir and thus docs directory will be used to download.

If self hosting crypto-js is used, you shoudl have a "assets/javascripts/cryptojs" folder with js files in your site_dir.

unverbuggt commented 1 year ago

wait... I think you found another bug...

please run pip install --upgrade mkdocs-encryptcontent-plugin again. I just pushed a fixed version to pip.

Duck5el commented 1 year ago

Great It is working now!!

Thanks for your quick help.