mkdocs-toggle-sidebar-plugin 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocs-toggle-sidebar-plugin-0.0.2/MANIFEST.in +2 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1/src/mkdocs_toggle_sidebar_plugin.egg-info → mkdocs-toggle-sidebar-plugin-0.0.2}/PKG-INFO +36 -11
- mkdocs-toggle-sidebar-plugin-0.0.2/README.md +73 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/setup.cfg +2 -2
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin/__init__.py +18 -4
- mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/material.js +25 -0
- mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/mkdocs.js +28 -0
- mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/readthedocs.js +27 -0
- mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js +60 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin.egg-info}/PKG-INFO +36 -11
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin.egg-info/SOURCES.txt +3 -0
- mkdocs-toggle-sidebar-plugin-0.0.1/MANIFEST.in +0 -2
- mkdocs-toggle-sidebar-plugin-0.0.1/README.md +0 -48
- mkdocs-toggle-sidebar-plugin-0.0.1/src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js +0 -61
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/LICENSE +0 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/pyproject.toml +0 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin.egg-info/dependency_links.txt +0 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin.egg-info/entry_points.txt +0 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin.egg-info/requires.txt +0 -0
- {mkdocs-toggle-sidebar-plugin-0.0.1 → mkdocs-toggle-sidebar-plugin-0.0.2}/src/mkdocs_toggle_sidebar_plugin.egg-info/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mkdocs-toggle-sidebar-plugin
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
|
|
5
5
|
Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
|
|
6
6
|
Author: six-two
|
|
7
7
|
Author-email: pip@six-two.dev
|
|
@@ -16,13 +16,21 @@ Requires-Python: >=3.9
|
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
|
|
19
|
-
# mkdocs-
|
|
19
|
+
# mkdocs-toggle-sidebar-plugin
|
|
20
20
|
|
|
21
21
|
[](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
|
|
22
22
|

|
|
23
23
|

|
|
24
24
|
|
|
25
|
-
This package allows you to
|
|
25
|
+
This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
|
|
26
|
+
|
|
27
|
+
- [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
|
|
28
|
+
- Builtin themes: `mkdocs`, `readthedocs`
|
|
29
|
+
|
|
30
|
+
The settings are stored using the `localStorage` object, so that it will persist between pages.
|
|
31
|
+
|
|
32
|
+
I wrote it after getting frustrated by the browser's `Find in page` function matching way to many links in the navigation sidebar instead of searching in the actual page's content.
|
|
33
|
+
|
|
26
34
|
|
|
27
35
|
## Usage
|
|
28
36
|
|
|
@@ -47,20 +55,37 @@ The plugin adds the following key bindings:
|
|
|
47
55
|
Key | Action
|
|
48
56
|
--- | ---
|
|
49
57
|
++b++ | toggle **b**oth (TOC and navigation)
|
|
50
|
-
++m++ | toggle navigation
|
|
51
|
-
++t++ | toggle
|
|
58
|
+
++m++ | toggle navigation **m**enu
|
|
59
|
+
++t++ | toggle **T**OC
|
|
52
60
|
|
|
53
61
|
## Theme support
|
|
54
62
|
|
|
55
|
-
Theme | Theme version |Plugin version | Status
|
|
56
|
-
--- | --- | ---
|
|
57
|
-
mkdocs-material | 9.1.21 | 0.0.1
|
|
58
|
-
mkdocs (default) | 1.5.2 | 0.0.
|
|
63
|
+
Theme | Theme version | Plugin version | Status
|
|
64
|
+
--- | --- | --- | ---
|
|
65
|
+
mkdocs-material | 9.1.21 | 0.0.1 | works
|
|
66
|
+
mkdocs (default) | 1.5.2 | 0.0.2 | works
|
|
67
|
+
readthedocs | 1.5.2 | 0.0.2 | works
|
|
59
68
|
|
|
60
69
|
Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
|
|
61
70
|
|
|
71
|
+
### Note to self
|
|
72
|
+
|
|
73
|
+
Test mkdocs-material theme:
|
|
74
|
+
```bash
|
|
75
|
+
./serve.sh
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Test mkdocs theme:
|
|
79
|
+
```bash
|
|
80
|
+
./serve.sh --theme mkdocs
|
|
81
|
+
```
|
|
82
|
+
|
|
62
83
|
## Notable changes
|
|
63
84
|
|
|
85
|
+
### Version 0.0.2
|
|
86
|
+
|
|
87
|
+
- Added support for `mkdocs` and `readthedocs` theme.
|
|
88
|
+
|
|
64
89
|
### Version 0.0.1
|
|
65
90
|
|
|
66
|
-
Prototype with `mkdocs-material` implementation.
|
|
91
|
+
- Prototype with `mkdocs-material` implementation.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# mkdocs-toggle-sidebar-plugin
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
|
|
8
|
+
|
|
9
|
+
- [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
|
|
10
|
+
- Builtin themes: `mkdocs`, `readthedocs`
|
|
11
|
+
|
|
12
|
+
The settings are stored using the `localStorage` object, so that it will persist between pages.
|
|
13
|
+
|
|
14
|
+
I wrote it after getting frustrated by the browser's `Find in page` function matching way to many links in the navigation sidebar instead of searching in the actual page's content.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Setup
|
|
20
|
+
|
|
21
|
+
First install the PyPI package:
|
|
22
|
+
```bash
|
|
23
|
+
pip install mkdocs-toggle-sidebar-plugin
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Add something like the following to your `mkdocs.yml`:
|
|
27
|
+
```yaml
|
|
28
|
+
plugins:
|
|
29
|
+
- search
|
|
30
|
+
- toggle-sidebar
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Key bindings
|
|
34
|
+
|
|
35
|
+
The plugin adds the following key bindings:
|
|
36
|
+
|
|
37
|
+
Key | Action
|
|
38
|
+
--- | ---
|
|
39
|
+
++b++ | toggle **b**oth (TOC and navigation)
|
|
40
|
+
++m++ | toggle navigation **m**enu
|
|
41
|
+
++t++ | toggle **T**OC
|
|
42
|
+
|
|
43
|
+
## Theme support
|
|
44
|
+
|
|
45
|
+
Theme | Theme version | Plugin version | Status
|
|
46
|
+
--- | --- | --- | ---
|
|
47
|
+
mkdocs-material | 9.1.21 | 0.0.1 | works
|
|
48
|
+
mkdocs (default) | 1.5.2 | 0.0.2 | works
|
|
49
|
+
readthedocs | 1.5.2 | 0.0.2 | works
|
|
50
|
+
|
|
51
|
+
Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
|
|
52
|
+
|
|
53
|
+
### Note to self
|
|
54
|
+
|
|
55
|
+
Test mkdocs-material theme:
|
|
56
|
+
```bash
|
|
57
|
+
./serve.sh
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Test mkdocs theme:
|
|
61
|
+
```bash
|
|
62
|
+
./serve.sh --theme mkdocs
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Notable changes
|
|
66
|
+
|
|
67
|
+
### Version 0.0.2
|
|
68
|
+
|
|
69
|
+
- Added support for `mkdocs` and `readthedocs` theme.
|
|
70
|
+
|
|
71
|
+
### Version 0.0.1
|
|
72
|
+
|
|
73
|
+
- Prototype with `mkdocs-material` implementation.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = mkdocs-toggle-sidebar-plugin
|
|
3
|
-
version = 0.0.
|
|
3
|
+
version = 0.0.2
|
|
4
4
|
author = six-two
|
|
5
5
|
author_email = pip@six-two.dev
|
|
6
|
-
description =
|
|
6
|
+
description = Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
|
|
7
7
|
long_description = file: README.md
|
|
8
8
|
long_description_content_type = text/markdown
|
|
9
9
|
url = https://github.com/six-two/mkdocs-toggle-sidebar-plugin
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import logging
|
|
2
3
|
# pip dependency
|
|
3
4
|
from mkdocs.plugins import BasePlugin
|
|
4
5
|
from mkdocs.config.defaults import MkDocsConfig
|
|
5
6
|
from mkdocs.config.base import Config
|
|
6
7
|
from mkdocs.config.config_options import Type, ExtraScriptValue
|
|
7
8
|
|
|
9
|
+
LOGGER = logging.getLogger("mkdocs.plugins.toggle-sidebar")
|
|
10
|
+
SCRIPT_DIR = os.path.dirname(__file__)
|
|
11
|
+
|
|
8
12
|
class PluginConfig(Config):
|
|
9
13
|
enabled = Type(bool, default=True)
|
|
10
14
|
show_toc_by_default = Type(bool, default=True)
|
|
@@ -19,7 +23,17 @@ class Plugin(BasePlugin[PluginConfig]):
|
|
|
19
23
|
Called once when the config is loaded.
|
|
20
24
|
It will make modify the config and initialize this plugin.
|
|
21
25
|
"""
|
|
26
|
+
self.theme_function_definitions = None
|
|
22
27
|
if self.config.enabled:
|
|
28
|
+
theme_name = config.theme.name or "mkdocs"
|
|
29
|
+
theme_path = os.path.join(SCRIPT_DIR, f"{theme_name}.js")
|
|
30
|
+
if os.path.exists(theme_path):
|
|
31
|
+
with open(theme_path) as f:
|
|
32
|
+
self.theme_function_definitions = f.read()
|
|
33
|
+
else:
|
|
34
|
+
LOGGER.warning(f"[toggle-sidebar] Theme '{theme_name}' is not (yet) supported. Hint:\n1. Try updating the plugin to the latest version: pip install -U mkdocs-toggle-sidebar-plugin\n2. Check if an issue for this theme exists: https://github.com/six-two/mkdocs-toggle-sidebar-plugin/issues\n3. If no issue exists feel free to open one. Please put the theme name and path where to download it in the issue")
|
|
35
|
+
|
|
36
|
+
if self.theme_function_definitions:
|
|
23
37
|
custom_script = ExtraScriptValue(self.config.javascript)
|
|
24
38
|
if self.config.async_:
|
|
25
39
|
custom_script.async_ = True
|
|
@@ -29,7 +43,7 @@ class Plugin(BasePlugin[PluginConfig]):
|
|
|
29
43
|
|
|
30
44
|
|
|
31
45
|
def on_post_build(self, config: MkDocsConfig) -> None:
|
|
32
|
-
if self.
|
|
46
|
+
if self.theme_function_definitions:
|
|
33
47
|
target_path = os.path.join(config.site_dir, self.config.javascript)
|
|
34
48
|
if os.path.exists(target_path):
|
|
35
49
|
# The file exists. This probably means, that the user wanted to override the default file
|
|
@@ -39,12 +53,12 @@ class Plugin(BasePlugin[PluginConfig]):
|
|
|
39
53
|
# Make sure that the folder exists
|
|
40
54
|
parent_dir = os.path.dirname(target_path)
|
|
41
55
|
os.makedirs(parent_dir, exist_ok=True)
|
|
42
|
-
|
|
56
|
+
|
|
43
57
|
# Copy the file, while also editing it on the fly
|
|
44
|
-
|
|
45
|
-
asset_path = os.path.join(current_dir, "toggle-sidebar.js")
|
|
58
|
+
asset_path = os.path.join(SCRIPT_DIR, "toggle-sidebar.js")
|
|
46
59
|
with open(asset_path) as f:
|
|
47
60
|
data = f.read()
|
|
61
|
+
data = data.replace("THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER", self.theme_function_definitions)
|
|
48
62
|
data = data.replace("TOC_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
|
|
49
63
|
data = data.replace("NAVIGATION_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
|
|
50
64
|
with open(target_path, "w") as f:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const setVisibility = (query_string, show) => {
|
|
2
|
+
for (let element of document.querySelectorAll(query_string)) {
|
|
3
|
+
element.style.display = show ? "block" : "none";
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const setTocVisibility = (visible) => {
|
|
8
|
+
setVisibility("div.md-sidebar.md-sidebar--secondary", visible);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const setNavigationVisibility = (visible) => {
|
|
12
|
+
setVisibility("div.md-sidebar.md-sidebar--primary", visible);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const registerKeyboardEventHandler = () => {
|
|
16
|
+
// Custom key handlers: SEE https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=key+bind#docsjavascriptsshortcutsjs
|
|
17
|
+
keyboard$.subscribe(key => {
|
|
18
|
+
if (key.mode === "global") {
|
|
19
|
+
if (coreEventListenerLogic(key.type)) {
|
|
20
|
+
// event handled, stop propagation
|
|
21
|
+
key.claim();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const setVisibility = (query_string, show) => {
|
|
2
|
+
for (let element of document.querySelectorAll(query_string)) {
|
|
3
|
+
element.style.display = show ? "" : "none";
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const setTocVisibility = (visible) => {
|
|
8
|
+
setVisibility("div.col-md-3", visible);
|
|
9
|
+
// Fix the page limitation when removing TOC
|
|
10
|
+
const main_div = document.querySelector("div.col-md-9");
|
|
11
|
+
main_div.style.maxWidth = visible ? "75%" : "100%";
|
|
12
|
+
main_div.style.flexBasis = visible ? "75%" : "100%";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const setNavigationVisibility = (visible) => {
|
|
16
|
+
setVisibility("ul.navbar-nav:nth-child(1)", visible);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const registerKeyboardEventHandler = () => {
|
|
20
|
+
// Native HTML key event handling
|
|
21
|
+
document.addEventListener("keydown", (event => {
|
|
22
|
+
if (coreEventListenerLogic(event.key)) {
|
|
23
|
+
// event handled, stop propagation
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
event.stopPropagation();
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const setVisibility = (query_string, show) => {
|
|
2
|
+
for (let element of document.querySelectorAll(query_string)) {
|
|
3
|
+
element.style.display = show ? "" : "none";
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const setTocVisibility = (visible) => {
|
|
8
|
+
setVisibility("nav.wy-nav-side", visible);
|
|
9
|
+
document.querySelector("div.wy-nav-content").style.maxWidth = visible ? "800px" : "1100px";
|
|
10
|
+
document.querySelector("section.wy-nav-content-wrap").style.marginLeft = visible ? "300px" : "0px";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const setNavigationVisibility = (visible) => {
|
|
14
|
+
// TOC and Navigation are merged / in one panel. So we just do nothing
|
|
15
|
+
// setTocVisibility(visible);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const registerKeyboardEventHandler = () => {
|
|
19
|
+
// Native HTML key event handling
|
|
20
|
+
document.addEventListener("keydown", (event => {
|
|
21
|
+
if (coreEventListenerLogic(event.key)) {
|
|
22
|
+
// event handled, stop propagation
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
const loadBool = (name, default_value) => {
|
|
3
|
+
const value = localStorage.getItem(`TOGGLE_SIDEBAR_${name}`);
|
|
4
|
+
if (value == null) {
|
|
5
|
+
return default_value;
|
|
6
|
+
} else {
|
|
7
|
+
return value == "1";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const saveBool = (name, value) => {
|
|
12
|
+
localStorage.setItem(`TOGGLE_SIDEBAR_${name}`, value ? "1" : "0");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const toggleTableOfContents = () => {
|
|
16
|
+
console.debug("Toggling table-of-contents sidebar");
|
|
17
|
+
const isShown = loadBool("TOC", TOC_DEFAULT_PLACEHOLDER);
|
|
18
|
+
setTocVisibility(!isShown);
|
|
19
|
+
saveBool("TOC", !isShown);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const toggleNavigation = () => {
|
|
23
|
+
console.debug("Toggling navigation sidebar");
|
|
24
|
+
const isShown = loadBool("NAVIGATION", NAVIGATION_DEFAULT_PLACEHOLDER);
|
|
25
|
+
setNavigationVisibility(!isShown);
|
|
26
|
+
saveBool("NAVIGATION", !isShown);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// START OF INCLUDE
|
|
30
|
+
// This gets replaced with the definitions of:
|
|
31
|
+
// - setTocVisibility(bool) -> void
|
|
32
|
+
// - setNavigationVisibility(bool) -> void
|
|
33
|
+
// - registerKeyboardEventHandler() -> void
|
|
34
|
+
THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER
|
|
35
|
+
// END OF INCLUDE
|
|
36
|
+
|
|
37
|
+
// argument: string, returns true if the key was handled and the event should be marked as already handled
|
|
38
|
+
const coreEventListenerLogic = (keyChar) => {
|
|
39
|
+
if (keyChar === "t") {
|
|
40
|
+
toggleTableOfContents();
|
|
41
|
+
return true;
|
|
42
|
+
} else if (keyChar === "m") {
|
|
43
|
+
toggleNavigation();
|
|
44
|
+
return true;
|
|
45
|
+
} else if (keyChar === "b") {
|
|
46
|
+
toggleNavigation();
|
|
47
|
+
toggleTableOfContents();
|
|
48
|
+
return true;
|
|
49
|
+
} else {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
window.addEventListener("load", () => {
|
|
55
|
+
console.log("The mkdocs-toggle-sidebar-plugin is installed. It adds the following key bindings:\n T -> toggle table of contents sidebar\n M -> toggle navigation menu sidebar\n B -> toggle both sidebars (TOC and navigation)");
|
|
56
|
+
registerKeyboardEventHandler();
|
|
57
|
+
setTocVisibility(loadBool("TOC", TOC_DEFAULT_PLACEHOLDER));
|
|
58
|
+
setNavigationVisibility(loadBool("NAVIGATION", NAVIGATION_DEFAULT_PLACEHOLDER));
|
|
59
|
+
});
|
|
60
|
+
}());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mkdocs-toggle-sidebar-plugin
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
|
|
5
5
|
Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
|
|
6
6
|
Author: six-two
|
|
7
7
|
Author-email: pip@six-two.dev
|
|
@@ -16,13 +16,21 @@ Requires-Python: >=3.9
|
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
|
|
19
|
-
# mkdocs-
|
|
19
|
+
# mkdocs-toggle-sidebar-plugin
|
|
20
20
|
|
|
21
21
|
[](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
|
|
22
22
|

|
|
23
23
|

|
|
24
24
|
|
|
25
|
-
This package allows you to
|
|
25
|
+
This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
|
|
26
|
+
|
|
27
|
+
- [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
|
|
28
|
+
- Builtin themes: `mkdocs`, `readthedocs`
|
|
29
|
+
|
|
30
|
+
The settings are stored using the `localStorage` object, so that it will persist between pages.
|
|
31
|
+
|
|
32
|
+
I wrote it after getting frustrated by the browser's `Find in page` function matching way to many links in the navigation sidebar instead of searching in the actual page's content.
|
|
33
|
+
|
|
26
34
|
|
|
27
35
|
## Usage
|
|
28
36
|
|
|
@@ -47,20 +55,37 @@ The plugin adds the following key bindings:
|
|
|
47
55
|
Key | Action
|
|
48
56
|
--- | ---
|
|
49
57
|
++b++ | toggle **b**oth (TOC and navigation)
|
|
50
|
-
++m++ | toggle navigation
|
|
51
|
-
++t++ | toggle
|
|
58
|
+
++m++ | toggle navigation **m**enu
|
|
59
|
+
++t++ | toggle **T**OC
|
|
52
60
|
|
|
53
61
|
## Theme support
|
|
54
62
|
|
|
55
|
-
Theme | Theme version |Plugin version | Status
|
|
56
|
-
--- | --- | ---
|
|
57
|
-
mkdocs-material | 9.1.21 | 0.0.1
|
|
58
|
-
mkdocs (default) | 1.5.2 | 0.0.
|
|
63
|
+
Theme | Theme version | Plugin version | Status
|
|
64
|
+
--- | --- | --- | ---
|
|
65
|
+
mkdocs-material | 9.1.21 | 0.0.1 | works
|
|
66
|
+
mkdocs (default) | 1.5.2 | 0.0.2 | works
|
|
67
|
+
readthedocs | 1.5.2 | 0.0.2 | works
|
|
59
68
|
|
|
60
69
|
Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
|
|
61
70
|
|
|
71
|
+
### Note to self
|
|
72
|
+
|
|
73
|
+
Test mkdocs-material theme:
|
|
74
|
+
```bash
|
|
75
|
+
./serve.sh
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Test mkdocs theme:
|
|
79
|
+
```bash
|
|
80
|
+
./serve.sh --theme mkdocs
|
|
81
|
+
```
|
|
82
|
+
|
|
62
83
|
## Notable changes
|
|
63
84
|
|
|
85
|
+
### Version 0.0.2
|
|
86
|
+
|
|
87
|
+
- Added support for `mkdocs` and `readthedocs` theme.
|
|
88
|
+
|
|
64
89
|
### Version 0.0.1
|
|
65
90
|
|
|
66
|
-
Prototype with `mkdocs-material` implementation.
|
|
91
|
+
- Prototype with `mkdocs-material` implementation.
|
|
@@ -4,6 +4,9 @@ README.md
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
setup.cfg
|
|
6
6
|
src/mkdocs_toggle_sidebar_plugin/__init__.py
|
|
7
|
+
src/mkdocs_toggle_sidebar_plugin/material.js
|
|
8
|
+
src/mkdocs_toggle_sidebar_plugin/mkdocs.js
|
|
9
|
+
src/mkdocs_toggle_sidebar_plugin/readthedocs.js
|
|
7
10
|
src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js
|
|
8
11
|
src/mkdocs_toggle_sidebar_plugin.egg-info/PKG-INFO
|
|
9
12
|
src/mkdocs_toggle_sidebar_plugin.egg-info/SOURCES.txt
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# mkdocs-crosslink-plugin
|
|
2
|
-
|
|
3
|
-
[](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
|
|
4
|
-

|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
This package allows you to add links to other MkDocs sites (or sites created with similar page generator).
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
### Setup
|
|
12
|
-
|
|
13
|
-
First install the PyPI package:
|
|
14
|
-
```bash
|
|
15
|
-
pip install mkdocs-toggle-sidebar-plugin
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Add something like the following to your `mkdocs.yml`:
|
|
19
|
-
```yaml
|
|
20
|
-
plugins:
|
|
21
|
-
- search
|
|
22
|
-
- toggle-sidebar
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Key bindings
|
|
26
|
-
|
|
27
|
-
The plugin adds the following key bindings:
|
|
28
|
-
|
|
29
|
-
Key | Action
|
|
30
|
-
--- | ---
|
|
31
|
-
++b++ | toggle **b**oth (TOC and navigation)
|
|
32
|
-
++m++ | toggle navigation menu
|
|
33
|
-
++t++ | toggle TOC
|
|
34
|
-
|
|
35
|
-
## Theme support
|
|
36
|
-
|
|
37
|
-
Theme | Theme version |Plugin version | Status
|
|
38
|
-
--- | --- | --- | ---
|
|
39
|
-
mkdocs-material | 9.1.21 | 0.0.1 | works
|
|
40
|
-
mkdocs (default) | 1.5.2 | 0.0.1 | not yet implemented
|
|
41
|
-
|
|
42
|
-
Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
|
|
43
|
-
|
|
44
|
-
## Notable changes
|
|
45
|
-
|
|
46
|
-
### Version 0.0.1
|
|
47
|
-
|
|
48
|
-
Prototype with `mkdocs-material` implementation.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
const setVisibility = (query_string, show) => {
|
|
3
|
-
for (let element of document.querySelectorAll(query_string)) {
|
|
4
|
-
element.style.display = show ? "block" : "none";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const loadBool = (name, default_value) => {
|
|
9
|
-
const value = localStorage.getItem(`TOGGLE_SIDEBAR_${name}`);
|
|
10
|
-
if (value == null) {
|
|
11
|
-
return default_value;
|
|
12
|
-
} else {
|
|
13
|
-
return value == "1";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const saveBool = (name, value) => {
|
|
18
|
-
localStorage.setItem(`TOGGLE_SIDEBAR_${name}`, value ? "1" : "0");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const setTocVisibility = (visible) => {
|
|
22
|
-
setVisibility("div.md-sidebar.md-sidebar--secondary", visible);
|
|
23
|
-
saveBool("TOC", visible);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const setNavigationVisibility = (visible) => {
|
|
27
|
-
setVisibility("div.md-sidebar.md-sidebar--primary", visible);
|
|
28
|
-
saveBool("NAVIGATION", visible);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const toggleTableOfContents = () => {
|
|
32
|
-
const isShown = loadBool("TOC", TOC_DEFAULT_PLACEHOLDER);
|
|
33
|
-
setTocVisibility(!isShown)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const toggleNavigation = () => {
|
|
37
|
-
console.debug("Toggling table-of-contents sitebar");
|
|
38
|
-
const isShown = loadBool("NAVIGATION", NAVIGATION_DEFAULT_PLACEHOLDER);
|
|
39
|
-
setNavigationVisibility(!isShown);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Custom key handlers: SEE https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=key+bind#docsjavascriptsshortcutsjs
|
|
43
|
-
keyboard$.subscribe(key => {
|
|
44
|
-
if (key.mode === "global") {
|
|
45
|
-
if (key.type === "t") {
|
|
46
|
-
key.claim();
|
|
47
|
-
toggleTableOfContents();
|
|
48
|
-
} else if (key.type === "m") {
|
|
49
|
-
key.claim();
|
|
50
|
-
toggleNavigation();
|
|
51
|
-
} else if (key.type === "b") {
|
|
52
|
-
key.claim();
|
|
53
|
-
toggleNavigation();
|
|
54
|
-
toggleTableOfContents();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
setTocVisibility(loadBool("TOC", TOC_DEFAULT_PLACEHOLDER));
|
|
60
|
-
setNavigationVisibility(loadBool("NAVIGATION", NAVIGATION_DEFAULT_PLACEHOLDER));
|
|
61
|
-
}());
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|