Skip to content

Commit

Permalink
Enable on-this-page highlight in news
Browse files Browse the repository at this point in the history
  • Loading branch information
doup committed Dec 5, 2024
1 parent 289aea0 commit 1e22335
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions sass/components/_tree-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
&, &:focus, &:active, &:hover, &:link, &:visited {
color: $color-white;
}

&[data-active=true] {
color: $color-white;
}
}

&__toggle {
Expand Down
3 changes: 2 additions & 1 deletion static/on-this-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ function otp_set_active(id_or_node){
id = id_or_node;
}
id = "#" + id;
console.info(id);
document.querySelectorAll(".on-this-page a").forEach(a => {
a.setAttribute("data-active", a.getAttribute("href") == id);
a.setAttribute("data-active", a.getAttribute("href").includes(id));
});
}

Expand Down
2 changes: 1 addition & 1 deletion templates/macros/news.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% endmacro %}
{% macro news_menu(toc, max_levels) %}
{% if toc %}
<ul class="tree-menu">
<ul class="tree-menu on-this-page">
{% for header in toc %}{{ self::news_menu_row(header=header, max_levels=max_levels, level=1) }}{% endfor %}
</ul>
{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions templates/news-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
{% block page_name %}Post{% endblock page_name %}
{% block mobile_page_menu %}{{ news_macros::news_menu(toc=page.toc, max_levels=1) }}{% endblock mobile_page_menu %}
{% block page_menu %}{{ news_macros::news_menu(toc=page.toc, max_levels=2) }}{% endblock page_menu %}

{% block head_extensions %}
<script defer src="/on-this-page.js"></script>
{% endblock head_extensions %}

{% block page_content %}
<h1 class="news-title">{{ page.title }}</h1>
<h2 class="news-subtitle">
Expand Down

0 comments on commit 1e22335

Please sign in to comment.