Skip to content

Commit 9b8db06

Browse files
committed
Version 2.0.0 experimental 1
1 parent 2e592cf commit 9b8db06

File tree

9 files changed

+411
-347
lines changed

9 files changed

+411
-347
lines changed

README.md

Lines changed: 52 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
**Usecase**
1010

11-
> I want to be able to protect my articles with password. And I would like this protection to be as granular as possible.
11+
> I want to be able to protect the content of the page with a password.
1212
>
13-
> It is possible to define a password to protect each article independently or a global password to encrypt all of them.
13+
> Define a password to protect each page independently or a global password to protect them all.
1414
>
15-
> If a global password exists, all articles and pages are encrypted with this password.
15+
> If a global password exists, all articles and pages are protected with this password.
1616
>
17-
> If a password is defined in an article or a page, it is always used even if a global password exists.
17+
> If a password is defined in an article or a page, it is always used even if there is a global password.
1818
>
19-
> If a password is defined as an empty character string, the page is not encrypted.
19+
> If a password is defined as an empty character string, the content is not protected.
20+
2021

2122

2223
# Table of Contents
@@ -26,13 +27,13 @@
2627
* [Global password protection](#global-password-protection)
2728
* [Customization](#extra-vars-customization)
2829
* [Features](#features)
29-
* [HighlightJS support](#highlightjs-support)
30-
* [Arithmatex support](#arithmatex-support)
31-
* [Tag encrypted page](#tag-encrypted-page)
30+
* [HighlightJS support](#highlightjs-support) *(default)*
31+
* [Arithmatex support](#arithmatex-support) *(default)*
32+
* [Tag encrypted page](#tag-encrypted-page) *(default)*
3233
* [Rebember password](#rebember-password)
33-
* [Add button](#add-button)
3434
* [Encrypt something](#encrypt-something)
3535
* [Search index encryption](#search-index-encryption)
36+
* [Add button](#add-button)
3637
* [Reload scripts](#reload-scripts)
3738
* [Contributing](#contributing)
3839

@@ -50,17 +51,17 @@ Install the package from source with pip:
5051
```bash
5152
cd mkdocs-encryptcontent-plugin/
5253
python3 setup.py sdist bdist_wheel
53-
pip3 install dist/mkdocs_encryptcontent_plugin-1.2.0.1-py3-none-any.whl
54+
pip3 install dist/mkdocs_encryptcontent_plugin-2.0.0.1-py3-none-any.whl
5455
```
5556

5657
Enable the plugin in your `mkdocs.yml`:
5758

5859
```yaml
5960
plugins:
60-
- search:
61+
- search: {}
6162
- encryptcontent: {}
6263
```
63-
> **Note:** If you have no `plugins` entry in your configuration file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set, but now you have to enable it explicitly.
64+
> **NOTE:** If you have no `plugins` entry in your configuration file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set, but now you have to enable it explicitly.
6465

6566
# Usage
6667

@@ -76,9 +77,9 @@ plugins:
7677
global_password: 'your_password'
7778
```
7879

79-
If a password is defined in an article, it will ALWAYS overwrite the global password.
80+
If a password is defined in an article, it will **ALWAYS** overwrite the global password.
8081

81-
> **NOTE** Keep in mind that if the `password:` tag exists without value in an article, it will not be protected !
82+
> **NOTE** Keep in mind that if the `password:` tag exists without value in an article, it will **not be protected** !
8283

8384
### Extra vars customization
8485

@@ -113,7 +114,7 @@ Defaut encryption information message is `Contact your administrator for access
113114

114115
> **Enable by default**
115116

116-
If HighlightJS module is detected in your theme to improve code color rendering, reload renderer after decryption process. If HighlightJS module is not correctly detected, you can force it by adding `hljs: True` on the plugin configuration or set False to disable detection.
117+
If HighlightJS module is detected in your theme to improve code color rendering, reload renderer after decryption process. If HighlightJS module is not correctly detected, you can force the detection by adding `hljs: True` on the plugin configuration or set `hljs: False` to disable this feature.
117118

118119
When enable the following part of the template is add to force reloading decrypted content.
119120

@@ -131,7 +132,7 @@ document.getElementById("mkdocs-decrypted-content").querySelectorAll('pre code')
131132

132133
Related to [issue #12](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/12)
133134

134-
If Arithmatex markdown extension is detected in your markdown extensions to improve math equations rendering, reload renderer after decryption process. If the Arithmatex markdown extension is not correctly detected, you can force it by adding `arithmatex: True` on the plugin configuration or set False to disable detection.
135+
If Arithmatex markdown extension is detected in your markdown extensions to improve math equations rendering, reload renderer after decryption process. If the Arithmatex markdown extension is not correctly detected, you can force the detection by adding `arithmatex: True` on the plugin configuration or set `arithmatex: False` to disable this feature.
135136

136137
When enable, the following part of the template is add to force math equations rendering on decrypted content.
137138

@@ -147,17 +148,11 @@ When enable, the following part of the template is add to force math equations r
147148

148149
Related to [issue #7](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/7)
149150

150-
You can add `tag_encrypted_page: False` in plugin configuration, to disable tagging of encrypted pages. This feature is neccessary for others feature working correctly. If you disable this feature, do no use [Encrypt Somethings](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin#encrypt-something),
151-
152151
This feature add an additional attribute `encrypted` with value `True` to the mkdocs type `mkdocs.nav.page` object.
153152

154-
```yaml
155-
plugins:
156-
- encryptcontent:
157-
tag_encrypted_page: False
158-
```
153+
You can add `tag_encrypted_page: False` in plugin configuration, to disable tagging of encrypted pages. **BUT** This feature is neccessary for others feature working correctly. If you disable this feature, do no use [Encrypt Somethings](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin#encrypt-something),
159154

160-
It becomes possible to use this attribute in the jinja template of your theme, as a condition to perform custom modification.
155+
When enable, it becomes possible to use `encrypted` attribute in the jinja template of your theme, as a condition to perform custom modification.
161156

162157
```jinja
163158
{%- for nav_item in nav %}
@@ -177,53 +172,35 @@ For example, in your template, you can use conditional check to add custom class
177172

178173
Related to [issue #6](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/6)
179174

180-
> :warning: **This feature is not really secure !** Password are store in clear text inside local cookie without httpOnly flag.
175+
> :warning: **This feature is not really secure !** Password are store in clear text inside local storage.
181176
>
182177
> Instead of using this feature, I recommend to use a password manager with its web plugins.
183178
> For example **KeepassXC** allows you, with a simple keyboard shortcut, to detect the password field `mkdocs-content-password` and to fill it automatically in a much more secure way.
184179

185180
If you do not have password manager, you can set `remember_password: True` in your `mkdocs.yml` to enable password remember feature.
186181

187-
When enabled, each time you fill password form and press `Enter` a cookie is create with your password as value.
188-
When you reload the page, if you already have an 'encryptcontent' cookie in your browser,
189-
the page will be automatically decrypted using the value of the cookie.
190-
191-
By default, the cookie is created with a `path=` relative to the page on which it was generated.
192-
This 'specific' cookie will always be used as first attempt to decrypt the current page when loading.
182+
When enabled, each time you fill password form and press `Enter` a key on local storage is create with your password
183+
as value. When you reload the page, if you already have an 'encryptcontent' key in the local storage of your browser,
184+
the page will be automatically decrypted using the value previously created.
193185

194-
If your password is a global password, you can fill in the `mkdocs-content-password` field,
195-
then use the keyboard shortcut `CTRL + ENTER` instead of the classic `ENTER`.
196-
The cookie that will be created with a `path=/` making it accessible, by default, on all the pages of your site.
186+
By default, the key is created with a name relative to the page on which it was generated.
187+
This 'relative' key will always be used as first attempt to decrypt the current page when loading.
197188

198-
The form of decryption remains visible as long as the content has not been successfully decrypted,
199-
which allows in case of error to modify the created cookie.
189+
If your password is a [global password](#global-password-protection), you can fill in the form field `mkdocs-content-password`, then use the keyboard shortcut `CTRL + ENTER` instead of the classic `ENTER`.
190+
The key that will be created with a generic name to making it accessible, by default, on all the pages of your site.
200191

201-
All cookies created with this feature have the default security options `Secure` and `SameSite=Strict`, just cause ...
192+
The form of decryption remains visible as long as the content has not been successfully decrypted, which allows in case of error to retry.
193+
All keys created with this feature on localstorage have an default expire time daly set to 24 hours, just cause ...
202194

203-
However *(optionally)*, its possible to remove these two security options by adding `disable_cookie_protection: True` in your `mkdocs.yml`.
204-
205-
Your configuration should look like this when you enabled this feature :
195+
However *(optionally)*, its possible to change the default expire time by setting options `default_expire_dalay: <number>` in your `mkdocs.yml`. Your configuration should look like this when you enabled this feature :
206196
```yaml
207197
plugins:
208198
- encryptcontent:
209199
remember_password: True
210-
disable_cookie_protection: True # <-- Really a bad idea
200+
default_expire_dalay: 24 # <-- Default expire delay in hours (optional)
211201
```
212202

213-
### Add button
214-
215-
Add `password_button: True` in plugin configuration variable, to add button to the right of the password field.
216-
217-
When enable, it allows to decrypt the content without creating a cookie *(if remember password feature is activated)*
218-
219-
Optionnally, you can add `password_button_text: 'custome_text_button'` to customize the button text.
220-
221-
```yaml
222-
plugins:
223-
- encryptcontent:
224-
password_button: True
225-
password_button_text: 'custome_text_button'
226-
```
203+
> **NOTE** The expired elements of the localStorage are only deleted by the execution of the decrypt-content.js scripts and therefore by the navigation on the site. Secret items can therefore remain visible in local storage after their expiration dates.
227204

228205
### Encrypt something
229206

@@ -252,7 +229,7 @@ Prefer to use an `'id'`, however depending on the template of your theme, it is
252229
So we can use the class attribute to define your unique name inside html tag.
253230
BeautifulSoup will encrypt all HTML elements discovered with the class.
254231

255-
When the feature is enabled, you can use any methods *(password, button, cookie)* to decrypt every elements encrypted on the page.
232+
When the feature is enabled, you can use any methods *(password, button, remember)* to decrypt every elements encrypted on the page.
256233

257234
By default **every child items** are encrypted and the encrypted elements have `style=display:none` to hide their content.
258235

@@ -311,10 +288,9 @@ plugins:
311288
mkdocs-encrypted-footer-meta: [div, id]
312289
```
313290

314-
315291
### Search index encryption
316292

317-
> **ALPHA VERSION**, use at your own risks. **ONLY** work with themes using default mkdocs search.
293+
> **Default value is "encrypted"**
318294

319295
Related to [issue #13](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/13)
320296

@@ -335,15 +311,30 @@ You can set `search_index: '<mode_name>'` in your `mkdocs.yml` to change the sea
335311

336312
```yaml
337313
plugins:
338-
- search:
339314
- encryptcontent:
340315
search_index: 'dynamically'
341316
```
342317

343-
This functionality overwrite the index creation function of the “search” plug-in provided by mkdocs. The modifications carried out make it possible to encrypt the content of the search index *after* the default plugin has carried out these treatments *(search configuration)*. It is therefore dependent on the default search plugin.
318+
This functionality overwrite the index creation function of the “search” plug-in provided by mkdocs. The modifications carried out make it possible to encrypt the content of the search index *after* the default plugin has carried out these treatments *(search configuration)*. It is therefore dependent on the default search plugin.
344319

345-
When the configuration mode is set to "**dynamically**", the javascripts contrib files of the default search plugin are also overloaded to include a process for decrypting and keeping the search index.
320+
When the configuration mode is set to "**dynamically**", the [javascripts contribution files](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/tree/experimental/encryptcontent/contrib/templates/search) are used to override the default search plugin files provided by MKdocs. They include a process of decrypting and keeping the search index in a SessionStorage.
346321

322+
> **NOTE** The mode 'dynamically' is currently **not compatible with Material Theme** !
323+
324+
### Add button
325+
326+
Add `password_button: True` in plugin configuration variable, to add button to the right of the password field.
327+
328+
When enable, it allows to decrypt the content just like the classic keypress ENTER. If remember password feature is activated, use button to decrypt generate a 'relative' key on your local storage. You cannot use password button to create global password value.
329+
330+
Optionnally, you can add `password_button_text: 'custom_text_button'` to customize the button text.
331+
332+
```yaml
333+
plugins:
334+
- encryptcontent:
335+
password_button: True
336+
password_button_text: 'custom_text_button'
337+
```
347338
348339
### Reload scripts
349340

encryptcontent/contrib/templates/search/lunr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* encryptcontent/contrib/templates/search/lunr.js */
12
/**
23
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9
34
* Copyright (C) 2020 Oliver Nightingale

encryptcontent/contrib/templates/search/main.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* encryptcontent/contrib/templates/search/main.js */
2+
13
function getSearchTermFromLocation() {
24
var sPageURL = window.location.search.substring(1);
35
var sURLVariables = sPageURL.split('&');
@@ -85,14 +87,11 @@ function onWorkerMessage (e) {
8587
}
8688
}
8789

88-
// reload index from session Storage if exist
89-
sessionIndex = sessionStorage.getItem('encryptcontent-index')
90-
9190
if (!window.Worker) {
92-
console.log('Web Worker API not supported');
9391
// load index in main thread
9492
$.getScript(joinUrl(base_url, "search/worker.js")).done(function () {
95-
console.log('Loaded worker');
93+
// reload index from session Storage if exist
94+
var sessionIndex = sessionStorage.getItem('encryptcontent-index')
9695
init(sessionIndex);
9796
window.postMessage = function (msg) {
9897
onWorkerMessage({data: msg});
@@ -101,8 +100,11 @@ if (!window.Worker) {
101100
console.error('Could not load worker.js');
102101
});
103102
} else {
103+
console.log('Web Worker API supported');
104104
// Wrap search in a web worker
105105
var searchWorker = new Worker(joinUrl(base_url, "search/worker.js"));
106-
searchWorker.postMessage({init: true, sessionIndex: sessionIndex});
106+
// reload index from session Storage if exist
107+
var sessionIndex = sessionStorage.getItem('encryptcontent-index')
107108
searchWorker.onmessage = onWorkerMessage;
109+
searchWorker.postMessage({init: true, sessionIndex: sessionIndex});
108110
}

encryptcontent/contrib/templates/search/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* encryptcontent/contrib/templates/search/worker.js */
2+
13
var base_path = 'function' === typeof importScripts ? '.' : '/search/';
24
var allowSearch = false;
35
var index;
@@ -7,7 +9,6 @@ var lang = ['en'];
79
var session = false;
810

911
function getScript(script, callback) {
10-
console.log('Loading script: ' + script);
1112
$.getScript(base_path + script).done(function () {
1213
callback();
1314
}).fail(function (jqxhr, settings, exception) {

0 commit comments

Comments
 (0)