unverbuggt / mkdocs-encryptcontent-plugin

A MkDocs plugin that encrypt/decrypt markdown content with AES

Home Page:https://unverbuggt.github.io/mkdocs-encryptcontent-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Hide the internal page ToC when not logged in.

martinbira opened this issue · comments

Even when not logged in, the interal ToC of a page is fully visible. Perhaps it should be hidden with the rest of the content as well.

Current behaviour:
1-current-behaviour-not-logged-in

Suggested behaviour:
2-suggested-behaviour-not-logged-in

Used package versions:
Python: 3.8.3
MkDocs: 1.1.2
Material: 5.5.3
mkdocs-encryptcontent-plugin: 0.0.3

I have tried several versions of this feature on a branch here feature/encrypt_toc

I am not satisfied with the operation with BS4, but I haven't found something more simple / functional with different themes ...
And cause I do not tried this feature on a lot of themes, there can still have some problems.
This feature is not present in pypi.org repositories for the moment and must be installed manually (clone && pip install).

Could you, please, give me a feedback before I consider merging this code on the branch master.

So I got it working after a while. At first I tried adding the id to the nav element in my theme. Then I recalled that you set the id on a div, so after a quick block extension it worked. For Material the site_nav block had to be extended in the main.html overrides:

{% block site_nav %}
  {% if nav %}
    <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
      <div class="md-sidebar__scrollwrap">
        <div class="md-sidebar__inner">
          {% include "partials/nav.html" %}
        </div>
      </div>
    </div>
  {% endif %}
  {% if page.toc %}
    <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
      <div class="md-sidebar__scrollwrap">
        {% if page.encrypted %}
        <div id="mkdocs-encrypted-toc" class="md-sidebar__inner">
          {% include "partials/toc.html" %}
        </div>
        {% else %}
        <div class="md-sidebar__inner">
          {% include "partials/toc.html" %}
        </div>
        {% endif %}
      </div>
    </div>
  {% endif %}
{% endblock %}

Pretty darn easy. Now I just gotta fix it for mobile as well, but it works!

And there I've got it working for mobile. Set that the page ToC in the mobile nav is always removed if '\x3cdiv id="mkdocs-encrypted-content"' is found in the page content. It does however result in that when the page is unlocked in mobile, the ToC is still not there. For our specific use case this is acceptable as mobile users of our site are less than 5% of all visitors, and the contents of our locked page is 100% desktop centered.

Thank you very much for this feedback.

Indeed I forgot the management of mobile versions ..
I'm not good with frontend development 🤪

However, even if it's okay for you, I want to try something to fix this problem.
Currently I have made changes to encrypt multiple 'div' / 'nav' ToC, based on a class name instead of an id.
It works very well, BUT it also gave me another idea which is much more interesting.

Maybe i can do a feature that will encrypt any part of your site.
The idea is that it takes the information in your config file as a list that will look like this :

encrypt_something:
  - <html tag>: <uniq id name>
  - div: mkdocs-encryptcontent-div-id
  - nav: mkdocs-encryptcontent-nav-id

For each of the listed elements, the HTML content would be encrypted, then hide with a hidden style.
At the time of the call of decrypt_content, loop over each elements to decrypt them all.

I'm gonna try to do this this afternoon or tomorrow.
I will give you a feedback on this post asap.

I made some change, still on feature\encrypt_toc even though the feature is completely different now.
Operation is described in documentation feature here

I admit it's much more complex than before ... but I think it's much more flexible and interesting.
I tried this on personal theme and Material theme, but only on certain html structures (div, nav).

I did not increase the version number of the plugin.

I tried the new setup, at least for the nav and yea, that solves all my issues without having to modify my site_nav block separately from the toc. Nice!

I made some change, still on feature\encrypt_toc even though the feature is completely different now. Operation is described in documentation feature here

I admit it's much more complex than before ... but I think it's much more flexible and interesting. I tried this on personal theme and Material theme, but only on certain html structures (div, nav).

I did not increase the version number of the plugin.

The links are broken. 😢

Thank you very much for this feedback.

Indeed I forgot the management of mobile versions .. I'm not good with frontend development 🤪

However, even if it's okay for you, I want to try something to fix this problem. Currently I have made changes to encrypt multiple 'div' / 'nav' ToC, based on a class name instead of an id. It works very well, BUT it also gave me another idea which is much more interesting.

Maybe i can do a feature that will encrypt any part of your site. The idea is that it takes the information in your config file as a list that will look like this :

encrypt_something:
  - <html tag>: <uniq id name>
  - div: mkdocs-encryptcontent-div-id
  - nav: mkdocs-encryptcontent-nav-id

For each of the listed elements, the HTML content would be encrypted, then hide with a hidden style. At the time of the call of decrypt_content, loop over each elements to decrypt them all.

I'm gonna try to do this this afternoon or tomorrow. I will give you a feedback on this post asap.

I tried to use encrypted_something to encrpt the ToC. But, when I enter the password, the ToC still dosen't show up.

I just want the feature like you said:

For each of the listed elements, the HTML content would be encrypted, then hide with a hidden style.
At the time of the call of decrypt_content, loop over each elements to decrypt them all.

@jeremy-feng

The documentation is here: documentation.

If you still want help after consulting the documentation, or if you encounter technical problems in use, you should open a new issue on git rather than comment on an already closed one.

Also remember to give us basic useful information to reproduce / diagnose your case, such as:

  • Your python version
  • Your version of mkdocs
  • Your plugin version
  • The theme you are using
  • Your configuration file