diff --git a/docs/_static/custom.css b/docs/_static/custom.css index 95c4150e2..815d61ba2 100644 --- a/docs/_static/custom.css +++ b/docs/_static/custom.css @@ -13,3 +13,7 @@ margin-bottom: 0.75ex; margin-top: 0.75ex; } + +.sidebar-tree a.current { + font-style: italic; +} diff --git a/docs/_static/custom.js b/docs/_static/custom.js new file mode 100644 index 000000000..605f58de3 --- /dev/null +++ b/docs/_static/custom.js @@ -0,0 +1,45 @@ +/* vim:fileencoding=utf-8 + * + * Copyright (C) 2021 Kovid Goyal + * + * Distributed under terms of the GPLv3 license + */ + +(function() { +"use strict"; + +function get_sidebar_tree() { + return document.querySelector('.sidebar-tree'); +} + +function mark_current_link(sidebar_tree, a, onload) { + console.log(onload); + var li = a.closest('li.has-children'); + while (li) { + li.querySelector('input[type=checkbox]').setAttribute('checked', 'checked'); + li = li.parentNode.closest('li.has-children'); + } + sidebar_tree.querySelectorAll('.current').forEach(function (elem) { + elem.classList.remove('current'); + }); + if (onload) a.scrollIntoView(); + a.classList.add('current'); +} + +function show_hash_in_sidebar(onload) { + var sidebar_tree = document.querySelector('.sidebar-tree'); + if (document.location.hash.length > 1) { + var a = sidebar_tree.querySelector('a[href="' + document.location.hash + '"]'); + if (a) mark_current_link(sidebar_tree, a, onload); + } else { + if (onload) sidebar_tree.querySelector('.current-page a').scrollIntoView(); + } +} + +document.addEventListener("DOMContentLoaded", function() { + show_hash_in_sidebar(true); + window.addEventListener('hashchange', show_hash_in_sidebar.bind(null, false)); +}); + +}()); + diff --git a/docs/conf.py b/docs/conf.py index cacbef0cd..a263ae77b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -131,6 +131,7 @@ html_theme_options: Dict[str, Any] = { html_static_path = ['_static'] html_favicon = html_logo = '../logo/kitty.svg' html_css_files = ['custom.css'] +html_js_files = ['custom.js'] # Custom sidebar templates, must be a dictionary that maps document names # to template names.