unverbuggt / mkdocs-encryptcontent-plugin

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

Build fails if `cache_file` points to an unexisting folder #59

Closed Guts closed 9 months ago

Guts commented 10 months ago

First of all, thank you for this very useful and comprehensive plugin! Nice work!

I'm facing an issue when trying to store the cache_file into a .cache/plugins/encryptcontent/ folder that does not exist at build time.

To reproduce

  1. Set cache_file to a path that does not exist yet:

    plugins:
    [...]
    - encryptcontent:
        global_password: !ENV MKDOCS_PLUGIN_ENCRYPT_PASSWORD
        cache_file:
          !ENV [
            MKDOCS_PLUGIN_ENCRYPT_CACHE_FILE,
            .cache/plugins/encryptcontent/encryptcontent.cache,
          ]
        title_prefix: ""
        password_button: true
        password_button_text: "Unlock content"
        remember_keys: true
        remember_password: true
        remember_prefix: encryptcontent_plugin_igv_scpo
  2. build: mkdocs build

It fails.

Error log

Traceback (most recent call last):
  File "/home/chapichapo/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/mkdocs/__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/mkdocs/commands/build.py", line 354, in build
    config.plugins.on_post_build(config=config)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/mkdocs/plugins.py", line 542, in on_post_build
    return self.run_event('post_build', config=config)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/mkdocs/plugins.py", line 509, in run_event
    result = method(**kwargs)
  File "/home/chapichapo/.venv/lib/python3.10/site-packages/encryptcontent/plugin.py", line 1117, in on_post_build
    with open(self.setup['cache_file'], 'w') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/home/chapichapo/.cache/plugins/encryptcontent/encryptcontent.cache'

Workaround

Create the folder before.

unverbuggt commented 10 months ago

Hi, thank you for pointing this out. I'll add a few lines to create the folder if it doesn't exist in the next release.