Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable on-this-page sidebar highlight in News #1910

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion static/on-this-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function otp_set_active(id_or_node){
let id = `#${id_or_node instanceof HTMLElement ? id_or_node.getAttribute("id") : id_or_node}`;

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
Loading