Skip to content

Commit c8b968d

Browse files
committed
Make doc navigation scroll to content on mobile
Closes #67.
1 parent 382916a commit c8b968d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

docs/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def create_navigation(current_path):
157157
title = data["title"]
158158

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

164164
return text
165165

docs/templates/article.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</div>
2828
<div class="sidebar-version">Bosca Ceoil Blue v%BOSCA_VERSION%</div>
2929
</div>
30-
<div class="content">
30+
<div class="content" id="_content">
3131
%PAGE_CONTENT%
3232
</div>
3333
</div>

docs/tools/paths.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import xml.etree.ElementTree as etree
1010

1111

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

2936

3037
def update_images(self, root: etree.Element):

0 commit comments

Comments
 (0)