-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const url = new URL(window.location.href) | ||
const menu = url.searchParams.get('menu') | ||
const child = url.searchParams.get('child') | ||
const menuItems = document.querySelectorAll('[data-nav="main"]') | ||
|
||
if (menu !== null) { | ||
menuItems.forEach(element => { | ||
element.classList.remove('active') | ||
}) | ||
|
||
const targetMainItems = document.querySelectorAll(`[data-nav-main="${menu}"]:not([data-nav-child])`) | ||
targetMainItems.forEach(element => { | ||
element.classList.add('active') | ||
}) | ||
|
||
const targetChildItems = document.querySelectorAll(`[data-nav-main="${menu}"][data-nav-child="${child}"]`) | ||
targetChildItems.forEach(element => { | ||
element.classList.add('active') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html{{ with site.LanguageCode | default site.Language.Lang }} lang="{{ . }}"{{ end }}> | ||
<head> | ||
<title>{{ .Permalink }}</title> | ||
<link rel="canonical" href="{{ .Permalink }}"> | ||
<meta name="robots" content="noindex"> | ||
<meta charset="utf-8"> | ||
<noscript><meta http-equiv="refresh" content="0; url={{ .Permalink }}"></noscript> | ||
<script src="/js/alias.js"></script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{- $menu := .menu -}} | ||
{{- $parent := .parent -}} | ||
{{- $page := .page -}} | ||
{{- $class := .class -}} | ||
|
||
{{- $menuURL := (or $menu.PageRef $menu.URL) | relLangURL -}} | ||
{{- $pageURL := $page.RelPermalink | relLangURL -}} | ||
{{- $isActive := hasPrefix $pageURL $menuURL -}} | ||
{{- $isAlias := $menu.Params.alias -}} | ||
|
||
{{- $url := urls.Parse $menuURL -}} | ||
{{- $baseURL := urls.Parse $.Site.Params.Baseurl -}} | ||
{{- $isExternal := ne $url.Host $baseURL.Host -}} | ||
{{- $externalHref := "" }} | ||
{{- if $isExternal }}{{ $externalHref = "target=\"_blank\" rel=\"noopener noreferrer\"" }}{{ end -}} | ||
|
||
{{- $mainNav := urlize (lower $menu.Name) -}} | ||
{{- $childNav := "" -}} | ||
|
||
{{- $button := "" -}} | ||
{{- if $parent -}} | ||
{{- $mainNav = urlize (lower $parent.Name) -}} | ||
{{- $childNav = urlize (lower $menu.Name) -}} | ||
{{- $class = printf "dropdown-item %s" $class -}} | ||
{{- else if $menu.HasChildren -}} | ||
{{- $class = printf "nav-link dropdown-toggle %s" $class -}} | ||
{{- $button = " role=\"button\" data-bs-toggle=\"dropdown\" aria-expanded=\"false\"" -}} | ||
{{- else -}} | ||
{{- $class = printf "nav-link %s" $class -}} | ||
{{- end -}} | ||
{{- $params := "" -}} | ||
{{- if and $isAlias (not $isExternal) -}} | ||
{{- $params = printf "?menu=%s" $mainNav -}} | ||
{{- with $childNav }}{{ $params = printf "%s&child=%s" $params . }}{{ end -}} | ||
{{- end -}} | ||
|
||
<a class="{{ $class }}{{ if $isActive }} active{{ end }}" | ||
data-nav="main" data-nav-main="{{ $mainNav }}"{{ with $childNav }} data-nav-child="{{ . }}"{{ end }} | ||
href="{{ $menuURL }}{{ $params | safeHTMLAttr }}"{{ with $externalHref }} {{ . | safeHTMLAttr }}{{ end }} {{ $button | safeHTMLAttr }}> | ||
|
||
{{- with $menu.Pre }}{{ . }}{{ end -}} | ||
<span {{ if $isActive }} class="active"{{ end }}>{{ $menu.Name }}</span> | ||
{{- with $menu.Post }}{{ . }}{{ end -}} | ||
{{- if $isExternal }} {{ partial "assets/icon.html" (dict "icon" "fas up-right-from-square fa-2xs") }}{{ end -}} | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const alias = document.querySelector("link[rel='canonical']").getAttribute('href') | ||
const params = window.location.search + window.location.hash | ||
window.location = alias + params |