Skip to content

Commit

Permalink
Revert hamburger menu creation which slipped in through backport 40aaed3
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler committed May 29, 2023
1 parent 40aaed3 commit 760d4d4
Showing 1 changed file with 15 additions and 69 deletions.
84 changes: 15 additions & 69 deletions tools/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def get_last_git_commit(src_dir, addon_path, is_addon):
<div id="container">
<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
<hr class="header">
"""

header_nopgm = """<h2>${PGM}</h2>
Expand Down Expand Up @@ -584,90 +585,42 @@ def escape_href(label):
return label.replace(" ", "-").lower()


def write_toc(data, hamburger_menu_toc=False):
"""Write Table of Contents
:param tuple data: parsed data from MyHTMLParser class instance
:param bool hamburger_menu_toc: write hamburger menu TOC for the
mobile, tablet screen
"""

def write_toc(data):
if not data:
return

fd = sys.stdout
if hamburger_menu_toc:
fd.write("<script>\n")
fd.write("// Create hamburger menu TOC HTML elements by the JavaScript\n")
fd.write("let temp = document.createElement('template');\n")
fd.write(
"""const toc = '<ul class="toc-mobile-screen" """
"""id="toc-mobile-screen">' + \n"""
)
else:
fd.write('<div class="toc">\n')
fd.write('<h4 class="toc">Table of contents</h4>\n')
fd.write('<ul class="toc">\n')
fd.write('<div class="toc">\n')
fd.write('<h4 class="toc">Table of contents</h4>\n')
fd.write('<ul class="toc">\n')
first = True
has_h2 = False
in_h3 = False
indent = 4
for tag, href, text in data:
if tag == "h3" and not in_h3 and has_h2:
if hamburger_menu_toc:
fd.write("'<ul>' + \n")
else:
fd.write('\n%s<ul class="toc">\n' % (" " * indent))
fd.write('\n%s<ul class="toc">\n' % (" " * indent))
indent += 4
in_h3 = True
elif not first:
if hamburger_menu_toc:
fd.write("'</li>' + \n")
else:
fd.write("</li>\n")
fd.write("</li>\n")

if tag == "h2":
has_h2 = True
if in_h3:
indent -= 4
if hamburger_menu_toc:
fd.write("'</ul></li>' + \n")
else:
fd.write("%s</ul></li>\n" % (" " * indent))
fd.write("%s</ul></li>\n" % (" " * indent))
in_h3 = False

text = text.replace("\xa0", " ")
if hamburger_menu_toc:
fd.write(
f"""'<li><a class="toc-item" href="#{escape_href(text)}">"""
f"{text}</a>' + \n"
)
else:
fd.write(
'%s<li class="toc"><a href="#%s" class="toc">%s</a>'
% (" " * indent, escape_href(text), text)
)
first = False

if hamburger_menu_toc:
fd.write(
"""'</li>' +
'<a class="close" href="#">' +
'<img src="./hamburger_menu_close.svg" alt="close">' +
'</a>' +
'</ul>' +
'<a class="hamburger" href="#toc-mobile-screen">' +
'<img src="./hamburger_menu.svg" alt="menu">' +
'</a>';
temp.innerHTML = toc;
const grassLogoLink = document.getElementsByTagName("img")[0];
grassLogoLink.after(temp.content);
</script>
"""
'%s<li class="toc"><a href="#%s" class="toc">%s</a>'
% (" " * indent, escape_href(text), text)
)
else:
fd.write("</li>\n</ul>\n")
fd.write("</div>\n")
first = False

fd.write("</li>\n</ul>\n")
fd.write("</div>\n")


def update_toc(data):
Expand Down Expand Up @@ -816,20 +769,13 @@ def get_addon_path():
)
if not re.search("<html>", tmp_data, re.IGNORECASE):
sys.stdout.write(header_tmpl.substitute(PGM=pgm, PGM_DESC=pgm_desc))

if tmp_data:
header_logo_img_el = '<img src="grass_logo.png" alt="GRASS logo">'
for line in tmp_data.splitlines(True):
# The cleanup happens on Makefile level too.
if not re.search(
"</body>|</html>|</div> <!-- end container -->", line, re.IGNORECASE
):
if header_logo_img_el in line:
sys.stdout.write(line)
# create hamburger menu TOC
write_toc(create_toc(src_data), hamburger_menu_toc=True)
else:
sys.stdout.write(line)
sys.stdout.write(line)

# create TOC
write_toc(create_toc(src_data))
Expand Down

0 comments on commit 760d4d4

Please sign in to comment.