Skip to content

Commit

Permalink
Merge pull request #547 from xerbalind/osredirect
Browse files Browse the repository at this point in the history
Fix mkdocs instant loading
  • Loading branch information
boegel authored Aug 14, 2023
2 parents 6cd034a + 7b4da7b commit 117bded
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
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

0 comments on commit 117bded

Please sign in to comment.