feat: add options to highlight active links and show current language

`highlight_active_link` and `show_language` added to `main_menu` in `params.toml`:

`main_menu = {align = "l", show_logo = true, highlight_active_link = true, show_language = false}`

For example, enables disabling highlighting active main menu links on scroll if it's found to be inaccurate in a certain case, such as towards the end of a homepage with lots of very short widgets that are linked in the menu.
This commit is contained in:
George Cushen committed 2020-06-17 20:29:03 +01:00
1 parent 4efb4d3ab0
commit 8d75e9e27a
3 files changed
+12 -5

No files matched your search

+1 -1
View File
@@ -147,7 +147,7 @@ address_format = "en-us"
############################
# Main menu alignment (l = left, c = center, r = right) and logo options.
main_menu = {align = "l", show_logo = true}
main_menu = {align = "l", show_logo = true, highlight_active_link = true, show_language = false}
# Show estimated reading time for posts? (true/false)
reading_time = true
+3 -1
View File
@@ -3,7 +3,9 @@
<html lang="{{$language_code}}" {{ if in site.Data.i18n.rtl.rtl $language_code }}dir="rtl"{{end}}>
{{ partial "site_head" . }}
<body id="top" data-spy="scroll" data-offset="70" data-target="{{ if or .IsHome (eq .Type "widget_page") }}#navbar-main{{else}}#TableOfContents{{end}}" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
{{- $highlight_active_link := site.Params.main_menu.highlight_active_link | default true -}}
<body id="top" data-spy="scroll" data-offset="70" data-target="{{ if or .IsHome (eq .Type "widget_page") | and $highlight_active_link }}#navbar-main{{else}}#TableOfContents{{end}}" {{ if not (.Scratch.Get "light") }}class="dark"{{end}}>
{{ partial "search" . }}
+8 -3
View File
@@ -1,4 +1,6 @@
{{ $current_page := . }}
{{ $highlight_active_link := site.Params.main_menu.highlight_active_link | default true }}
{{ $show_current_language := site.Params.main_menu.show_language | default false }}
{{/* Get site logo. */}}
{{ $show_logo := site.Params.main_menu.show_logo | default true }}
@@ -90,7 +92,7 @@
{{ end }}
<li class="nav-item">
<a class="nav-link {{if $is_link_in_current_path }} active{{end}}" href="{{.URL | relLangURL}}"{{ if and $is_widget_page $is_same_page }} data-target="{{$hash}}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
<a class="nav-link {{if and $highlight_active_link $is_link_in_current_path }} active{{end}}" href="{{.URL | relLangURL}}"{{ if and $is_widget_page $is_same_page }} data-target="{{$hash}}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
{{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
</a>
</li>
@@ -151,8 +153,11 @@
{{ if .IsTranslated }}
<li class="nav-item dropdown i18n-dropdown">
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true">
<i class="fas fa-globe mr-1" aria-hidden="true"></i><span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
<a href="#" class="nav-link {{ if $show_current_language }}dropdown-toggle{{end}}" data-toggle="dropdown" aria-haspopup="true">
<i class="fas fa-globe mr-1" aria-hidden="true"></i>
{{- if $show_current_language -}}
<span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
{{- end -}}
</a>
<div class="dropdown-menu">
<div class="dropdown-item dropdown-item-active">