Skip to content

Commit c28e4ce

Browse files
committed
Version 2.2.1
1 parent 68383b8 commit c28e4ce

File tree

5 files changed

+23
-63
lines changed

5 files changed

+23
-63
lines changed

.gitignore

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# mkdocs-encryptcontent-plugin
22

3+
[![PyPI Version][pypi-v-image]][pypi-v-link]
4+
[![PyPI downloads](https://img.shields.io/pypi/dm/mkdocs-encryptcontent-plugin.svg)](https://pypi.org/project/mkdocs-encryptcontent-plugin)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6+
37
This plugin allows you to have password protected articles and pages in MKdocs.
48

59
The content is encrypted with AES-256 in Python using PyCryptodome, and decrypted in the browser with Crypto-JS.
@@ -18,6 +22,8 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte
1822
>
1923
> If a password is defined as an empty character string, the content is not protected.
2024
25+
![encryptcontent_demo](https://user-images.githubusercontent.com/12155947/177001700-f0920d4b-0c41-4d11-8164-9f63d29d8a6a.gif)
26+
2127

2228
# Table of Contents
2329

@@ -52,7 +58,7 @@ Install the package from source with pip:
5258
```bash
5359
cd mkdocs-encryptcontent-plugin/
5460
python3 setup.py sdist bdist_wheel
55-
pip3 install dist/mkdocs_encryptcontent_plugin-2.2.0-py3-none-any.whl
61+
pip3 install dist/mkdocs_encryptcontent_plugin-2.2.1-py3-none-any.whl
5662
```
5763

5864
Enable the plugin in your `mkdocs.yml`:
@@ -212,19 +218,6 @@ For example, in your theme template, you can use conditional check to add custom
212218
<a {% if nav_item.encrypted %}class="mkdocs-encrypted-class"{% endif %}href="{{ nav_item.url|url }}">{{ nav_item.title }}</a>
213219
```
214220

215-
### Add button
216-
217-
Add `password_button: True` in plugin config variable, to add button to the right of the password field decrypt the content.
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-
```
227-
228221
### Rebember password
229222

230223
Related to [issue #6](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/6)
@@ -425,3 +418,7 @@ If you want to contribute to the code of this project, please read the [Contribu
425418
[mkdocs-plugins]: https://www.mkdocs.org/dev-guide/plugins/
426419
[github-issues]: https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues
427420
[contributing]: CONTRIBUTING.md
421+
422+
<!-- Badges -->
423+
[pypi-v-image]: https://img.shields.io/pypi/v/mkdocs-encryptcontent-plugin.svg
424+
[pypi-v-link]: https://pypi.org/project/mkdocs-encryptcontent-plugin/

encryptcontent/contrib/templates/search/main.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ function joinUrl (base, path) {
2323
return base + "/" + path;
2424
}
2525

26+
function escapeHtml (value) {
27+
return value.replace(/&/g, '&amp;')
28+
.replace(/"/g, '&quot;')
29+
.replace(/</g, '&lt;')
30+
.replace(/>/g, '&gt;');
31+
}
32+
2633
function formatResult (location, title, summary) {
27-
return '<article><h3><a href="' + joinUrl(base_url, location) + '">'+ title + '</a></h3><p>' + summary +'</p></article>';
34+
return '<article><h3><a href="' + joinUrl(base_url, location) + '">'+ escapeHtml(title) + '</a></h3><p>' + escapeHtml(summary) +'</p></article>';
2835
}
2936

3037
function displayResults (results) {

encryptcontent/plugin.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def on_pre_build(self, config, **kwargs):
220220
try:
221221
if self.config['search_index'] in ['encrypted', 'dynamically']:
222222
from mkdocs.contrib.search.search_index import SearchIndex, ContentParser
223-
224223
def _create_entry_for_section(self, section, toc, abs_url, password=None):
225224
toc_item, text = self._find_toc_by_id(toc, section.id), ''
226225
if not self.config.get('indexing') or self.config['indexing'] == 'full':
@@ -232,25 +231,20 @@ def _create_entry_for_section(self, section, toc, abs_url, password=None):
232231
if toc_item is not None:
233232
self._add_entry(title=toc_item.title, text=text, loc=abs_url + toc_item.url)
234233
SearchIndex.create_entry_for_section = _create_entry_for_section
235-
236234
def _add_entry_from_context(self, page):
237235
parser, url, text = ContentParser(), page.url, ''
238236
parser.feed(page.content)
239237
parser.close()
240238
if not self.config.get('indexing') or self.config['indexing'] == 'full':
241239
text = parser.stripped_html.rstrip('\n')
242-
if (hasattr(page, 'encrypted') and hasattr(page, 'password')
243-
and page.password is not None): # noqa: W503
240+
if (hasattr(page, 'encrypted') and hasattr(page, 'password') and page.password is not None):
244241
plugin = config['plugins']['encryptcontent']
245242
code = plugin.__encrypt_text_aes__(text, str(page.password))
246243
text = b';'.join(code).decode('ascii')
247244
self._add_entry(title=page.title, text=text, loc=url)
248-
if (self.config.get('indexing')
249-
and self.config['indexing'] in ['full', 'sections']): # noqa: W503
245+
if (self.config.get('indexing') and self.config['indexing'] in ['full', 'sections']):
250246
for section in parser.data:
251-
if (hasattr(page, 'encrypted')
252-
and hasattr(page, 'password') # noqa: W503
253-
and page.password is not None): # noqa: W503, E127
247+
if (hasattr(page, 'encrypted') and hasattr(page, 'password') and page.password is not None):
254248
self.create_entry_for_section(section, page.toc, url, page.password)
255249
else:
256250
self.create_entry_for_section(section, page.toc, url)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def read(fname):
1111

1212
setup(
1313
name='mkdocs-encryptcontent-plugin',
14-
version='2.2.0',
14+
version='2.2.1',
1515
author='CoinK0in',
1616
author_email='[email protected]',
1717
description='A MkDocs plugin that encrypt/decrypt markdown content with AES',

0 commit comments

Comments
 (0)