mkdocs-toggle-sidebar-plugin 0.0.2__tar.gz → 0.0.4__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.
Files changed (24) hide show
  1. mkdocs_toggle_sidebar_plugin-0.0.4/PKG-INFO +134 -0
  2. mkdocs_toggle_sidebar_plugin-0.0.4/README.md +115 -0
  3. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/setup.cfg +1 -1
  4. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin/__init__.py +9 -2
  5. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin/material.js +61 -0
  6. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin/mkdocs.js +69 -0
  7. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin/readthedocs.js +67 -0
  8. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js +122 -0
  9. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin.egg-info/PKG-INFO +134 -0
  10. mkdocs-toggle-sidebar-plugin-0.0.2/PKG-INFO +0 -91
  11. mkdocs-toggle-sidebar-plugin-0.0.2/README.md +0 -73
  12. mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/material.js +0 -25
  13. mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/mkdocs.js +0 -28
  14. mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/readthedocs.js +0 -27
  15. mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js +0 -60
  16. mkdocs-toggle-sidebar-plugin-0.0.2/src/mkdocs_toggle_sidebar_plugin.egg-info/PKG-INFO +0 -91
  17. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/LICENSE +0 -0
  18. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/MANIFEST.in +0 -0
  19. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/pyproject.toml +0 -0
  20. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin.egg-info/SOURCES.txt +0 -0
  21. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin.egg-info/dependency_links.txt +0 -0
  22. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin.egg-info/entry_points.txt +0 -0
  23. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin.egg-info/requires.txt +0 -0
  24. {mkdocs-toggle-sidebar-plugin-0.0.2 → mkdocs_toggle_sidebar_plugin-0.0.4}/src/mkdocs_toggle_sidebar_plugin.egg-info/top_level.txt +0 -0
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.1
2
+ Name: mkdocs-toggle-sidebar-plugin
3
+ Version: 0.0.4
4
+ Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
5
+ Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
+ Author: six-two
7
+ Author-email: pip@six-two.dev
8
+ License: MIT License
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: mkdocs>=1.4.0
19
+
20
+ # mkdocs-toggle-sidebar-plugin
21
+
22
+ [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
23
+ ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
24
+ ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
25
+
26
+ This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
27
+
28
+ - [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
29
+ - Builtin themes: `mkdocs`, `readthedocs`
30
+
31
+ You can play around with it and these themes on the [test page](https://mkdocs-toggle-sidebar.six-two.dev).
32
+
33
+ The settings are stored using the `localStorage` object, so that it will persist between pages.
34
+
35
+ 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.
36
+
37
+
38
+ ## Usage
39
+
40
+ ### Setup
41
+
42
+ First install the PyPI package:
43
+ ```bash
44
+ pip install mkdocs-toggle-sidebar-plugin
45
+ ```
46
+
47
+ Add something like the following to your `mkdocs.yml`:
48
+ ```yaml
49
+ plugins:
50
+ - search
51
+ - toggle-sidebar
52
+ ```
53
+
54
+ ### Key bindings
55
+
56
+ The plugin adds the following key bindings:
57
+
58
+ Key | Action
59
+ --- | ---
60
+ `b` | toggle **b**oth (TOC and navigation)
61
+ `m` | toggle navigation **m**enu
62
+ `t` | toggle **T**OC
63
+
64
+ For some themes like `readthedocs` navigation and TOC are combined.
65
+ In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
66
+
67
+ ### Toggle button
68
+
69
+ When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
70
+ It is usually in the nav or the top bar.
71
+ Clicking the button will toggle the navigation, table of contents, or both (depending on the supplied value).
72
+ By leaving the field empty or setting it to `none`, no button is added.
73
+
74
+ ### Exported API functions
75
+
76
+ This plugin exposes some JavaScript functions, that can show, hide or toggle the visibility of the sidebars.
77
+ You can see how they are called in `docs/javascript-functions.md` and how they are defined in `src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js`.
78
+
79
+ In short there are:
80
+
81
+ - `MkdocsToggleSidebarPlugin.setNavigationVisibility(show: bool)`
82
+ - `MkdocsToggleSidebarPlugin.setTocVisibility(show: bool)`
83
+ - `MkdocsToggleSidebarPlugin.setAllVisibility: (showNavigation: bool, showTOC: bool)`
84
+ - `MkdocsToggleSidebarPlugin.toggleNavigationVisibility()`
85
+ - `MkdocsToggleSidebarPlugin.toggleTocVisibility()`
86
+ - `MkdocsToggleSidebarPlugin.toggleAllVisibility()`
87
+
88
+ The names and parameters should be self-explanatory.
89
+
90
+ ## Theme support
91
+
92
+ Below shows the latest themes that I have tested.
93
+ They are not updated that often, and the plugin should generally work for other of theme versions too.
94
+
95
+ Theme | Theme version | Plugin version | Status
96
+ --- | --- | --- | ---
97
+ mkdocs-material | 9.5.34 | 0.0.4 | works
98
+ mkdocs (default) | 1.6.1 | 0.0.4 | works
99
+ readthedocs | 1.6.1 | 0.0.4 | works
100
+
101
+ Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
102
+
103
+ ### Note to self
104
+
105
+ Test mkdocs-material theme:
106
+ ```bash
107
+ ./serve.sh
108
+ ```
109
+
110
+ Test mkdocs theme:
111
+ ```bash
112
+ ./serve.sh --theme mkdocs
113
+ ```
114
+
115
+ ## Notable changes
116
+
117
+ ### Version 0.0.4
118
+
119
+ - Export API via `MkdocsToggleSidebarPlugin` object.
120
+ This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
121
+ - Added `toggle_button` option and implemented it for Material theme
122
+
123
+ ### Version 0.0.3
124
+
125
+ - Changed internal API:
126
+ - Element hiding/restyling is now done via CSS, so it is easier to undo. You should no longer have problems on devices with small screens (like phones) having broken layouts.
127
+
128
+ ### Version 0.0.2
129
+
130
+ - Added support for `mkdocs` and `readthedocs` theme.
131
+
132
+ ### Version 0.0.1
133
+
134
+ - Prototype with `mkdocs-material` implementation.
@@ -0,0 +1,115 @@
1
+ # mkdocs-toggle-sidebar-plugin
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
4
+ ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
5
+ ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
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
+ You can play around with it and these themes on the [test page](https://mkdocs-toggle-sidebar.six-two.dev).
13
+
14
+ The settings are stored using the `localStorage` object, so that it will persist between pages.
15
+
16
+ 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.
17
+
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+
23
+ First install the PyPI package:
24
+ ```bash
25
+ pip install mkdocs-toggle-sidebar-plugin
26
+ ```
27
+
28
+ Add something like the following to your `mkdocs.yml`:
29
+ ```yaml
30
+ plugins:
31
+ - search
32
+ - toggle-sidebar
33
+ ```
34
+
35
+ ### Key bindings
36
+
37
+ The plugin adds the following key bindings:
38
+
39
+ Key | Action
40
+ --- | ---
41
+ `b` | toggle **b**oth (TOC and navigation)
42
+ `m` | toggle navigation **m**enu
43
+ `t` | toggle **T**OC
44
+
45
+ For some themes like `readthedocs` navigation and TOC are combined.
46
+ In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
47
+
48
+ ### Toggle button
49
+
50
+ When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
51
+ It is usually in the nav or the top bar.
52
+ Clicking the button will toggle the navigation, table of contents, or both (depending on the supplied value).
53
+ By leaving the field empty or setting it to `none`, no button is added.
54
+
55
+ ### Exported API functions
56
+
57
+ This plugin exposes some JavaScript functions, that can show, hide or toggle the visibility of the sidebars.
58
+ You can see how they are called in `docs/javascript-functions.md` and how they are defined in `src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js`.
59
+
60
+ In short there are:
61
+
62
+ - `MkdocsToggleSidebarPlugin.setNavigationVisibility(show: bool)`
63
+ - `MkdocsToggleSidebarPlugin.setTocVisibility(show: bool)`
64
+ - `MkdocsToggleSidebarPlugin.setAllVisibility: (showNavigation: bool, showTOC: bool)`
65
+ - `MkdocsToggleSidebarPlugin.toggleNavigationVisibility()`
66
+ - `MkdocsToggleSidebarPlugin.toggleTocVisibility()`
67
+ - `MkdocsToggleSidebarPlugin.toggleAllVisibility()`
68
+
69
+ The names and parameters should be self-explanatory.
70
+
71
+ ## Theme support
72
+
73
+ Below shows the latest themes that I have tested.
74
+ They are not updated that often, and the plugin should generally work for other of theme versions too.
75
+
76
+ Theme | Theme version | Plugin version | Status
77
+ --- | --- | --- | ---
78
+ mkdocs-material | 9.5.34 | 0.0.4 | works
79
+ mkdocs (default) | 1.6.1 | 0.0.4 | works
80
+ readthedocs | 1.6.1 | 0.0.4 | works
81
+
82
+ Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
83
+
84
+ ### Note to self
85
+
86
+ Test mkdocs-material theme:
87
+ ```bash
88
+ ./serve.sh
89
+ ```
90
+
91
+ Test mkdocs theme:
92
+ ```bash
93
+ ./serve.sh --theme mkdocs
94
+ ```
95
+
96
+ ## Notable changes
97
+
98
+ ### Version 0.0.4
99
+
100
+ - Export API via `MkdocsToggleSidebarPlugin` object.
101
+ This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
102
+ - Added `toggle_button` option and implemented it for Material theme
103
+
104
+ ### Version 0.0.3
105
+
106
+ - Changed internal API:
107
+ - Element hiding/restyling is now done via CSS, so it is easier to undo. You should no longer have problems on devices with small screens (like phones) having broken layouts.
108
+
109
+ ### Version 0.0.2
110
+
111
+ - Added support for `mkdocs` and `readthedocs` theme.
112
+
113
+ ### Version 0.0.1
114
+
115
+ - Prototype with `mkdocs-material` implementation.
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = mkdocs-toggle-sidebar-plugin
3
- version = 0.0.2
3
+ version = 0.0.4
4
4
  author = six-two
5
5
  author_email = pip@six-two.dev
6
6
  description = Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
@@ -1,18 +1,21 @@
1
1
  import os
2
2
  import logging
3
3
  # pip dependency
4
- from mkdocs.plugins import BasePlugin
4
+ from mkdocs.plugins import BasePlugin, get_plugin_logger
5
5
  from mkdocs.config.defaults import MkDocsConfig
6
6
  from mkdocs.config.base import Config
7
7
  from mkdocs.config.config_options import Type, ExtraScriptValue
8
+ from mkdocs.exceptions import PluginError
8
9
 
9
- LOGGER = logging.getLogger("mkdocs.plugins.toggle-sidebar")
10
+ LOGGER = get_plugin_logger(__name__)
10
11
  SCRIPT_DIR = os.path.dirname(__file__)
12
+ ALLOWED_TOGGLE_BUTTON_VALUES = ["none", "navigation", "toc", "all"]
11
13
 
12
14
  class PluginConfig(Config):
13
15
  enabled = Type(bool, default=True)
14
16
  show_toc_by_default = Type(bool, default=True)
15
17
  show_navigation_by_default = Type(bool, default=True)
18
+ toggle_button = Type(str, default="none")
16
19
  async_ = Type(bool, default=True)
17
20
  javascript = Type(str, default="assets/javascripts/toggle-sidebar.js")
18
21
 
@@ -39,6 +42,9 @@ class Plugin(BasePlugin[PluginConfig]):
39
42
  custom_script.async_ = True
40
43
 
41
44
  config.extra_javascript.append(custom_script)
45
+
46
+ if self.config.toggle_button not in ALLOWED_TOGGLE_BUTTON_VALUES:
47
+ raise PluginError(f"Unexpected value for 'toggle_button': '{self.config.toggle_button}'. Allowed values are {', '.join(ALLOWED_TOGGLE_BUTTON_VALUES)}")
42
48
  return config
43
49
 
44
50
 
@@ -61,6 +67,7 @@ class Plugin(BasePlugin[PluginConfig]):
61
67
  data = data.replace("THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER", self.theme_function_definitions)
62
68
  data = data.replace("TOC_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
63
69
  data = data.replace("NAVIGATION_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
70
+ data = data.replace("TOGGLE_BUTTON_PLACEHOLDER", self.config.toggle_button)
64
71
  with open(target_path, "w") as f:
65
72
  f.write(data)
66
73
 
@@ -0,0 +1,61 @@
1
+ const setCombinedVisibility = (showNavigation, showTOC) => {
2
+ let style = `
3
+ .mkdocs-toggle-sidebar-button {
4
+ cursor: pointer;
5
+ margin-right: 5px;
6
+ margin-left: 1rem;
7
+ }
8
+
9
+ /*
10
+ Hide the button when on mobile (and menu us shown as hamburger menu anyways).
11
+ The exact max-width is taken from the styling of the 'body > header > nav > a' element
12
+ */
13
+
14
+ @media screen and (max-width: 76.1875em) {
15
+ .mkdocs-toggle-sidebar-button {
16
+ display: none;
17
+ }
18
+ }
19
+ `;
20
+ if (!showTOC) {
21
+ style += `
22
+ div.md-sidebar.md-sidebar--secondary {
23
+ display: none;
24
+ }
25
+ `;
26
+ }
27
+
28
+ if (!showNavigation) {
29
+ style += `
30
+ div.md-sidebar.md-sidebar--primary {
31
+ display: none;
32
+ }
33
+ `
34
+ }
35
+
36
+ return style;
37
+ }
38
+
39
+ const addToggleButton = (toggleNavigation, toggleTOC) => {
40
+ const toggleBtn = createDefaultToggleButton(toggleNavigation, toggleTOC);
41
+ toggleBtn.classList.add("md-icon");
42
+
43
+ const titleElement = document.querySelector(".md-header__title");
44
+ if (titleElement) {
45
+ titleElement.parentNode.insertBefore(toggleBtn, titleElement.nextSibling);
46
+ } else {
47
+ console.warn(TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING);
48
+ }
49
+ }
50
+
51
+ const registerKeyboardEventHandler = () => {
52
+ // Custom key handlers: SEE https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=key+bind#docsjavascriptsshortcutsjs
53
+ keyboard$.subscribe(key => {
54
+ if (key.mode === "global") {
55
+ if (coreEventListenerLogic(key.type)) {
56
+ // event handled, stop propagation
57
+ key.claim();
58
+ }
59
+ }
60
+ });
61
+ }
@@ -0,0 +1,69 @@
1
+ const setCombinedVisibility = (showNavigation, showTOC) => {
2
+ let style = `
3
+ .mkdocs-toggle-sidebar-container {
4
+ margin: auto 0;
5
+ }
6
+
7
+ .mkdocs-toggle-sidebar-button {
8
+ cursor: pointer;
9
+ width: 1.5em;
10
+ padding-bottom: 2px;
11
+ }
12
+
13
+ .mkdocs-toggle-sidebar-button svg {
14
+ fill: white;
15
+ }
16
+ `;
17
+
18
+ if (!showTOC) {
19
+ style += `
20
+ div.col-md-3 {
21
+ display: none;
22
+ }
23
+
24
+ div.col-md-9 {
25
+ max-width: 100%;
26
+ flex-basis: 100%;
27
+ }
28
+ `;
29
+ }
30
+
31
+ if (!showNavigation) {
32
+ style += `
33
+ ul.navbar-nav:nth-child(1) {
34
+ display: none;
35
+ }
36
+ `
37
+ }
38
+
39
+ return style;
40
+ }
41
+
42
+ const addToggleButton = (toggleNavigation, toggleTOC) => {
43
+ const toggleBtn = createDefaultToggleButton(toggleNavigation, toggleTOC);
44
+ const li = document.createElement("li");
45
+ li.className = "nav-item mkdocs-toggle-sidebar-container";
46
+ li.append(toggleBtn);
47
+
48
+ let titleElement = document.querySelector("#navbar-collapse > ul.nav.navbar-nav.ms-md-auto");
49
+ if (!titleElement) {
50
+ // This worked in older versions, but not anymore. Since the default check failed, maybe we are in an old version?
51
+ titleElement = document.querySelector("#navbar-collapse > ul.nav.navbar-nav.ml-auto");
52
+ }
53
+ if (titleElement) {
54
+ titleElement.insertBefore(li, titleElement.firstChild);
55
+ } else {
56
+ console.warn(TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING);
57
+ }
58
+ }
59
+
60
+ const registerKeyboardEventHandler = () => {
61
+ // Native HTML key event handling
62
+ document.addEventListener("keydown", (event => {
63
+ if (coreEventListenerLogic(event.key)) {
64
+ // event handled, stop propagation
65
+ event.preventDefault();
66
+ event.stopPropagation();
67
+ }
68
+ }));
69
+ }
@@ -0,0 +1,67 @@
1
+ const setCombinedVisibility = (showNavigation, showTOC) => {
2
+ // Navigation and TOC are merged so we just pick one of the values and trust them
3
+ // @TODO: add support for combined bars in toggle-sidebar.js?
4
+ let style = `
5
+ .mkdocs-toggle-sidebar-button {
6
+ cursor: pointer;
7
+ width: 1em;
8
+ fill: darkgray;
9
+ display: flex;
10
+ margin-right: 5px;
11
+ }
12
+
13
+ /* Hide toggle button in mobile view */
14
+ @media screen and (max-width: 768px) {
15
+ .wy-breadcrumbs > li.mkdocs-toggle-sidebar-container {
16
+ display: none;
17
+ }
18
+ }
19
+ `;
20
+ if (!showNavigation) {
21
+ // We can not hide the contents in mobile view, since then the hamburger menu would be empty
22
+ style += `
23
+ @media screen and (min-width: 768px) {
24
+ section.wy-nav-content-wrap {
25
+ margin-left: 0px;
26
+ }
27
+
28
+ nav.wy-nav-side, div.rst-versions {
29
+ display: none;
30
+ }
31
+
32
+ div.wy-nav-content {
33
+ max-width: 1100px;
34
+ }
35
+ }
36
+ `;
37
+ }
38
+
39
+ return style;
40
+
41
+ }
42
+
43
+ const addToggleButton = (toggleNavigation, toggleTOC) => {
44
+ const toggleBtn = createDefaultToggleButton(toggleNavigation, toggleTOC);
45
+ toggleBtn.title = "Toggle Navigation"; // There is only one real sidebar, so we use this name for consistency
46
+ const li = document.createElement("li");
47
+ li.className = "mkdocs-toggle-sidebar-container";
48
+ li.append(toggleBtn);
49
+
50
+ const titleElement = document.querySelector("ul.wy-breadcrumbs");
51
+ if (titleElement) {
52
+ titleElement.insertBefore(li, titleElement.firstChild);
53
+ } else {
54
+ console.warn(TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING);
55
+ }
56
+ }
57
+
58
+ const registerKeyboardEventHandler = () => {
59
+ // Native HTML key event handling
60
+ document.addEventListener("keydown", (event => {
61
+ if (coreEventListenerLogic(event.key)) {
62
+ // event handled, stop propagation
63
+ event.preventDefault();
64
+ event.stopPropagation();
65
+ }
66
+ }));
67
+ }
@@ -0,0 +1,122 @@
1
+ (function() {
2
+ const customDynamicStyle = document.createElement("style");
3
+ document.head.appendChild(customDynamicStyle);
4
+
5
+ const TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING = "[mkdocs-toggle-sidebar-plugin] Reference element for inserting 'toggle_button' not found. This version of the plugin may not be compatible with this version of the theme. Try updating both to the latest version. If that fails, you can open an GitHub issue.";
6
+
7
+ const loadBool = (name, default_value) => {
8
+ const value = localStorage.getItem(`TOGGLE_SIDEBAR_${name}`);
9
+ if (value == null) {
10
+ return default_value;
11
+ } else {
12
+ return value == "1";
13
+ }
14
+ }
15
+
16
+ const loadNavigationState = () => loadBool("NAVIGATION", NAVIGATION_DEFAULT_PLACEHOLDER);
17
+ const loadTocState = () => loadBool("TOC", TOC_DEFAULT_PLACEHOLDER);
18
+
19
+ const saveBool = (name, value) => {
20
+ localStorage.setItem(`TOGGLE_SIDEBAR_${name}`, value ? "1" : "0");
21
+ }
22
+
23
+ const toggleVisibility = (toggleNavigation, toggleTOC) => {
24
+ let newNavigation = loadNavigationState();
25
+ let newTOC = loadTocState();
26
+
27
+ if (toggleNavigation) {
28
+ newNavigation = !newNavigation;
29
+ saveBool("NAVIGATION", newNavigation);
30
+ }
31
+ if (toggleTOC) {
32
+ newTOC = !newTOC;
33
+ saveBool("TOC", newTOC);
34
+ }
35
+
36
+ _setVisibility(newNavigation, newTOC);
37
+ }
38
+
39
+ const _setVisibility = (newNavigation, newTOC) => {
40
+ console.debug(`Setting new visibility: navigation=${newNavigation}, TOC=${newTOC}`);
41
+ // combine this into one operation, so that it is more efficient (for toggling both) and easier to code with dynamic CSS generation
42
+ customDynamicStyle.innerHTML = setCombinedVisibility(newNavigation, newTOC);
43
+ }
44
+
45
+ // START OF INCLUDE
46
+ // This gets replaced with the definitions of:
47
+ // - setCombinedVisibility(showNavigation: bool, showTOC: bool) -> string (dynamic CSS)
48
+ // - registerKeyboardEventHandler() -> void
49
+ THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER
50
+ // END OF INCLUDE
51
+
52
+ // argument: string, returns true if the key was handled and the event should be marked as already handled
53
+ const coreEventListenerLogic = (keyChar) => {
54
+ if (keyChar === "t") {
55
+ toggleVisibility(false, true);
56
+ return true;
57
+ } else if (keyChar === "m") {
58
+ toggleVisibility(true, false);
59
+ return true;
60
+ } else if (keyChar === "b") {
61
+ toggleVisibility(true, true);
62
+ return true;
63
+ } else {
64
+ return false;
65
+ }
66
+ }
67
+
68
+ window.addEventListener("load", () => {
69
+ 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)");
70
+
71
+ const toggle_button = "TOGGLE_BUTTON_PLACEHOLDER";
72
+ if (toggle_button == "none") {
73
+ // do nothing
74
+ } else if (toggle_button == "navigation") {
75
+ addToggleButton(true, false);
76
+ } else if (toggle_button == "toc") {
77
+ addToggleButton(false, true);
78
+ } else if (toggle_button == "all") {
79
+ addToggleButton(true, true);
80
+ } else {
81
+ console.error(`[mkdocs-toggle-sidebar-plugin] Unknown value for toggle_button: '${toggleButtonType}'`);
82
+ }
83
+
84
+ registerKeyboardEventHandler();
85
+ customDynamicStyle.innerHTML = setCombinedVisibility(loadNavigationState(), loadTocState());
86
+ });
87
+
88
+ const createDefaultToggleButton = (toggleNavigation, toggleTOC) => {
89
+ const toggleBtn = document.createElement("div");
90
+ toggleBtn.className = "mkdocs-toggle-sidebar-button";
91
+ toggleBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"></path></svg>`;
92
+ if (toggleNavigation && toggleTOC) {
93
+ toggleBtn.title = "Toggle Navigation and Table of Contents";
94
+ } else if (toggleNavigation) {
95
+ toggleBtn.title = "Toggle Navigation";
96
+ } else if (toggleTOC) {
97
+ toggleBtn.title = "Toggle Table of Contents";
98
+ }
99
+ toggleBtn.addEventListener("click", () => toggleVisibility(toggleNavigation, toggleTOC));
100
+ return toggleBtn;
101
+ };
102
+
103
+ // Export functions that the user can call to modify the state
104
+ window.MkdocsToggleSidebarPlugin = {
105
+ setNavigationVisibility: (show) => {
106
+ saveBool("NAVIGATION", show);
107
+ _setVisibility(show, loadTocState());
108
+ },
109
+ setTocVisibility: (show) => {
110
+ saveBool("TOC", show);
111
+ _setVisibility(loadNavigationState(), show);
112
+ },
113
+ setAllVisibility: (showNavigation, showTOC) => {
114
+ saveBool("NAVIGATION", showNavigation);
115
+ saveBool("TOC", showTOC);
116
+ _setVisibility(showNavigation, showTOC);
117
+ },
118
+ toggleNavigationVisibility: () => toggleVisibility(true, false),
119
+ toggleTocVisibility: () => toggleVisibility(false, true),
120
+ toggleAllVisibility: () => toggleVisibility(true, true)
121
+ };
122
+ }());
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.1
2
+ Name: mkdocs-toggle-sidebar-plugin
3
+ Version: 0.0.4
4
+ Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
5
+ Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
+ Author: six-two
7
+ Author-email: pip@six-two.dev
8
+ License: MIT License
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: mkdocs>=1.4.0
19
+
20
+ # mkdocs-toggle-sidebar-plugin
21
+
22
+ [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
23
+ ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
24
+ ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
25
+
26
+ This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
27
+
28
+ - [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
29
+ - Builtin themes: `mkdocs`, `readthedocs`
30
+
31
+ You can play around with it and these themes on the [test page](https://mkdocs-toggle-sidebar.six-two.dev).
32
+
33
+ The settings are stored using the `localStorage` object, so that it will persist between pages.
34
+
35
+ 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.
36
+
37
+
38
+ ## Usage
39
+
40
+ ### Setup
41
+
42
+ First install the PyPI package:
43
+ ```bash
44
+ pip install mkdocs-toggle-sidebar-plugin
45
+ ```
46
+
47
+ Add something like the following to your `mkdocs.yml`:
48
+ ```yaml
49
+ plugins:
50
+ - search
51
+ - toggle-sidebar
52
+ ```
53
+
54
+ ### Key bindings
55
+
56
+ The plugin adds the following key bindings:
57
+
58
+ Key | Action
59
+ --- | ---
60
+ `b` | toggle **b**oth (TOC and navigation)
61
+ `m` | toggle navigation **m**enu
62
+ `t` | toggle **T**OC
63
+
64
+ For some themes like `readthedocs` navigation and TOC are combined.
65
+ In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
66
+
67
+ ### Toggle button
68
+
69
+ When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
70
+ It is usually in the nav or the top bar.
71
+ Clicking the button will toggle the navigation, table of contents, or both (depending on the supplied value).
72
+ By leaving the field empty or setting it to `none`, no button is added.
73
+
74
+ ### Exported API functions
75
+
76
+ This plugin exposes some JavaScript functions, that can show, hide or toggle the visibility of the sidebars.
77
+ You can see how they are called in `docs/javascript-functions.md` and how they are defined in `src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js`.
78
+
79
+ In short there are:
80
+
81
+ - `MkdocsToggleSidebarPlugin.setNavigationVisibility(show: bool)`
82
+ - `MkdocsToggleSidebarPlugin.setTocVisibility(show: bool)`
83
+ - `MkdocsToggleSidebarPlugin.setAllVisibility: (showNavigation: bool, showTOC: bool)`
84
+ - `MkdocsToggleSidebarPlugin.toggleNavigationVisibility()`
85
+ - `MkdocsToggleSidebarPlugin.toggleTocVisibility()`
86
+ - `MkdocsToggleSidebarPlugin.toggleAllVisibility()`
87
+
88
+ The names and parameters should be self-explanatory.
89
+
90
+ ## Theme support
91
+
92
+ Below shows the latest themes that I have tested.
93
+ They are not updated that often, and the plugin should generally work for other of theme versions too.
94
+
95
+ Theme | Theme version | Plugin version | Status
96
+ --- | --- | --- | ---
97
+ mkdocs-material | 9.5.34 | 0.0.4 | works
98
+ mkdocs (default) | 1.6.1 | 0.0.4 | works
99
+ readthedocs | 1.6.1 | 0.0.4 | works
100
+
101
+ Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
102
+
103
+ ### Note to self
104
+
105
+ Test mkdocs-material theme:
106
+ ```bash
107
+ ./serve.sh
108
+ ```
109
+
110
+ Test mkdocs theme:
111
+ ```bash
112
+ ./serve.sh --theme mkdocs
113
+ ```
114
+
115
+ ## Notable changes
116
+
117
+ ### Version 0.0.4
118
+
119
+ - Export API via `MkdocsToggleSidebarPlugin` object.
120
+ This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
121
+ - Added `toggle_button` option and implemented it for Material theme
122
+
123
+ ### Version 0.0.3
124
+
125
+ - Changed internal API:
126
+ - Element hiding/restyling is now done via CSS, so it is easier to undo. You should no longer have problems on devices with small screens (like phones) having broken layouts.
127
+
128
+ ### Version 0.0.2
129
+
130
+ - Added support for `mkdocs` and `readthedocs` theme.
131
+
132
+ ### Version 0.0.1
133
+
134
+ - Prototype with `mkdocs-material` implementation.
@@ -1,91 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mkdocs-toggle-sidebar-plugin
3
- Version: 0.0.2
4
- Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
5
- Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
- Author: six-two
7
- Author-email: pip@six-two.dev
8
- License: MIT License
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: POSIX :: Linux
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Requires-Python: >=3.9
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
-
19
- # mkdocs-toggle-sidebar-plugin
20
-
21
- [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
22
- ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
23
- ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
24
-
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
-
34
-
35
- ## Usage
36
-
37
- ### Setup
38
-
39
- First install the PyPI package:
40
- ```bash
41
- pip install mkdocs-toggle-sidebar-plugin
42
- ```
43
-
44
- Add something like the following to your `mkdocs.yml`:
45
- ```yaml
46
- plugins:
47
- - search
48
- - toggle-sidebar
49
- ```
50
-
51
- ### Key bindings
52
-
53
- The plugin adds the following key bindings:
54
-
55
- Key | Action
56
- --- | ---
57
- ++b++ | toggle **b**oth (TOC and navigation)
58
- ++m++ | toggle navigation **m**enu
59
- ++t++ | toggle **T**OC
60
-
61
- ## Theme support
62
-
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
68
-
69
- Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
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
-
83
- ## Notable changes
84
-
85
- ### Version 0.0.2
86
-
87
- - Added support for `mkdocs` and `readthedocs` theme.
88
-
89
- ### Version 0.0.1
90
-
91
- - Prototype with `mkdocs-material` implementation.
@@ -1,73 +0,0 @@
1
- # mkdocs-toggle-sidebar-plugin
2
-
3
- [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
4
- ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
5
- ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
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,25 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
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
- }
@@ -1,27 +0,0 @@
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
- }
@@ -1,60 +0,0 @@
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,91 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mkdocs-toggle-sidebar-plugin
3
- Version: 0.0.2
4
- Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
5
- Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
- Author: six-two
7
- Author-email: pip@six-two.dev
8
- License: MIT License
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: POSIX :: Linux
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Requires-Python: >=3.9
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
-
19
- # mkdocs-toggle-sidebar-plugin
20
-
21
- [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
22
- ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
23
- ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
24
-
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
-
34
-
35
- ## Usage
36
-
37
- ### Setup
38
-
39
- First install the PyPI package:
40
- ```bash
41
- pip install mkdocs-toggle-sidebar-plugin
42
- ```
43
-
44
- Add something like the following to your `mkdocs.yml`:
45
- ```yaml
46
- plugins:
47
- - search
48
- - toggle-sidebar
49
- ```
50
-
51
- ### Key bindings
52
-
53
- The plugin adds the following key bindings:
54
-
55
- Key | Action
56
- --- | ---
57
- ++b++ | toggle **b**oth (TOC and navigation)
58
- ++m++ | toggle navigation **m**enu
59
- ++t++ | toggle **T**OC
60
-
61
- ## Theme support
62
-
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
68
-
69
- Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
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
-
83
- ## Notable changes
84
-
85
- ### Version 0.0.2
86
-
87
- - Added support for `mkdocs` and `readthedocs` theme.
88
-
89
- ### Version 0.0.1
90
-
91
- - Prototype with `mkdocs-material` implementation.