Skip to content

Commit

Permalink
Make doc navigation scroll to content on mobile
Browse files Browse the repository at this point in the history
Closes #67.
  • Loading branch information
YuriSizov committed Jan 16, 2025
1 parent 382916a commit c8b968d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def create_navigation(current_path):
title = data["title"]

if current_path == data["outpath"]:
text += f'<a href="{url}" class="navigation-item active">{title}</a>\n'
text += f'<a href="#_content" class="navigation-item active">{title}</a>\n'
else:
text += f'<a href="{url}" class="navigation-item">{title}</a>\n'
text += f'<a href="{url}#_content" class="navigation-item">{title}</a>\n'

return text

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
<div class="sidebar-version">Bosca Ceoil Blue v%BOSCA_VERSION%</div>
</div>
<div class="content">
<div class="content" id="_content">
%PAGE_CONTENT%
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion docs/tools/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xml.etree.ElementTree as etree


# Convert link and image paths that start with "/" to absolute paths using configured base.
class AbsoluteLinkProcessor(Treeprocessor):
def __init__(self, md, config):
super().__init__(md)
Expand All @@ -24,7 +25,13 @@ def run(self, root: etree.Element):
def update_links(self, root: etree.Element):
for el in root.iter("a"):
if "href" in el.attrib and el.attrib["href"].startswith("/"):
el.attrib["href"] = self.base_path + el.attrib["href"]
path = self.base_path + el.attrib["href"]
# Make sure the content is immediately visible on mobile, but only
# if there are no other hashes in the URL.
if path.endswith(".html"):
path += "#_content"

el.attrib["href"] = path


def update_images(self, root: etree.Element):
Expand Down

0 comments on commit c8b968d

Please sign in to comment.