Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mkdocs instant loading #547

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions custom_plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,3 @@
)
</script>
"""

# loop over all
# <a class="headerlink" from text
# <a class="md-nav__link"> from index and TOC
# strip the OS from the href of all of them if the localstorage has select_OS defined
JS_OS_NEUTRAL = """
<script>
if (!! localStorage.getItem('select_OS')) {
const classes = ["headerlink", "md-nav__link"]
for (i in classes) {
var anchors = Array.from(document.getElementsByClassName(classes[i]))
anchors.forEach(
function (anch) {
//console.log("i", i, "class", classes[i], "anch.href", anch.href)
if (!!anch.href) {
anch.href = anch.href.replace(/\/(Linux|macOS|Windows)\//i, "/")
}
})
}
}
</script>
"""
4 changes: 1 addition & 3 deletions custom_plugin/custom_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mkdocs.structure.pages import Page
from yaml import safe_load

from constants import JS_SCROLL_STR, OS_PICK_BTN, OS_PICK_STR, JS_OS_NEUTRAL
from constants import JS_SCROLL_STR, OS_PICK_BTN, OS_PICK_STR

"""
See https://www.mkdocs.org/user-guide/plugins/#developing-plugins for some more information
Expand Down Expand Up @@ -237,8 +237,6 @@ def on_post_page(self, output: str, page: Page, config: Config):
"""
if self.os_pick:
output += JS_SCROLL_STR
if self.osneutrallinks:
output += JS_OS_NEUTRAL
return output

def on_post_build(self, config: Config):
Expand Down