From 109d094dc2ee4e311e20da415bc8d18c1424dc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 7 Feb 2025 22:00:13 +0100 Subject: [PATCH] menu: support for link effects #1008 --- docs/config/_default/hugo.toml | 22 +++++ .../partials/_relearn/imageAttributes.gotmpl | 4 +- .../partials/_relearn/linkAttributes.gotmpl | 4 +- layouts/partials/menu.html | 80 ++++++++++++++----- layouts/partials/version.txt | 2 +- 5 files changed, 87 insertions(+), 25 deletions(-) diff --git a/docs/config/_default/hugo.toml b/docs/config/_default/hugo.toml index ad7a8dc82e..19fdef5821 100644 --- a/docs/config/_default/hugo.toml +++ b/docs/config/_default/hugo.toml @@ -138,11 +138,13 @@ summaryLength = 10 pre = ' ' name = 'Hugo' url = 'https://gohugo.io/documentation/' + weight = 1 [[languages.en.menu.devshortcuts]] parent = 'devshortcuts' pre = ' ' identifier = 'theme' name = 'Theme' + weight = 2 [[languages.en.menu.devshortcuts.params]] alwaysopen = true [[languages.en.menu.devshortcuts]] @@ -150,18 +152,27 @@ summaryLength = 10 pre = ' ' identifier = 'configoptions' pageRef = 'configuration/reference' + weight = 1 [[languages.en.menu.devshortcuts]] parent = 'theme' pre = ' ' identifier = 'frontmatter' title = 'Front Matter Reference' pageRef = 'authoring/frontmatter/reference#annotated-front-matter' + weight = 2 [[languages.en.menu.devshortcuts]] parent = 'theme' pre = ' ' identifier = 'screenshotframe' title = 'Screenshot Frame' pageRef = 'images/hero.zip' + weight = 3 + [[languages.en.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + title = 'Maaagic Download' + pageRef = 'images/magic.gif?download' + weight = 4 # this is ourrr way t' showcase th' multilang settings by # doing autotrrranlat'n of th' english content; we are @@ -216,11 +227,13 @@ summaryLength = 10 pre = ' ' name = "Cap'n Hugo" url = 'https://gohugo.io/documentation/' + weight = 1 [[languages.pir.menu.devshortcuts]] parent = 'devshortcuts' pre = ' ' identifier = 'theme' name = "Th' Theme" + weight = 2 [[languages.pir.menu.devshortcuts.params]] alwaysopen = true [[languages.pir.menu.devshortcuts]] @@ -228,18 +241,27 @@ summaryLength = 10 pre = ' ' identifier = 'configoptions' pageRef = 'configuration/reference' + weight = 1 [[languages.pir.menu.devshortcuts]] parent = 'theme' pre = ' ' identifier = 'frontmatter' title = 'Front Matter Reference' pageRef = 'authoring/frontmatter/reference#annotated-front-matter' + weight = 2 [[languages.pir.menu.devshortcuts]] parent = 'theme' pre = ' ' identifier = 'screenshotframe' title = 'Screenshot Frame' pageRef = 'images/hero.zip' + weight = 3 + [[languages.pir.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + title = 'Maaagic Download' + pageRef = 'images/magic.gif?download' + weight = 4 # mounts are only needed in this showcase to access the publicly available screenshots and CHANGELOG; # remove this section if you don't need further mounts diff --git a/layouts/partials/_relearn/imageAttributes.gotmpl b/layouts/partials/_relearn/imageAttributes.gotmpl index 6ad73f485e..e105483920 100644 --- a/layouts/partials/_relearn/imageAttributes.gotmpl +++ b/layouts/partials/_relearn/imageAttributes.gotmpl @@ -1,4 +1,4 @@ -{{- $attributes := dict }} +{{- $attributes := .attributes | default dict }} {{- $height := "auto" }} {{- $width := "auto" }} {{- $effects := dict "border" false "lazy" true "lightbox" true "shadow" false }} @@ -63,7 +63,7 @@ {{- end }} {{- end }} {{- end }} -{{- if $attributes.class }}{{ $classes = $classes | append $attributes.class }}{{ end }} +{{- if $attributes.class }}{{ $classes = $classes | append (split $attributes.class " ") }}{{ end }} {{- $attributes = merge $attributes (dict "class" (delimit $classes " ")) }} {{- $attributes = merge $attributes (dict "src" .url) }} {{- $attributes = merge $attributes (dict "style" (printf " height: %s; width: %s;%s" $height $width (index $attributes "style" | default ""))) }} diff --git a/layouts/partials/_relearn/linkAttributes.gotmpl b/layouts/partials/_relearn/linkAttributes.gotmpl index 6827516620..275ef167d9 100644 --- a/layouts/partials/_relearn/linkAttributes.gotmpl +++ b/layouts/partials/_relearn/linkAttributes.gotmpl @@ -1,4 +1,4 @@ -{{- $attributes := dict }} +{{- $attributes := .attributes | default dict }} {{- /* target will be boolean false if no user defined value was set and effect default should be applied */}} {{- $target := false }} {{- $u := urls.Parse .url }} @@ -64,7 +64,7 @@ {{- end }} {{- end }} {{- end }} -{{- if $attributes.class }}{{ $classes = $classes | append $attributes.class }}{{ end }} +{{- if $attributes.class }}{{ $classes = $classes | append (split $attributes.class " ") }}{{ end }} {{- $attributes = merge $attributes (dict "class" (delimit $classes " ")) }} {{- $attributes = merge $attributes (dict "href" .url) }} {{- $attributes = merge $attributes (dict "download" $effects.download) }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 7200275666..a6db00ee51 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -169,7 +169,6 @@ {{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }} {{- $url := partial "permalink.gotmpl" (dict "to" .) }} {{- $isCrosslink := false }} - {{- $target := "" }} {{- if .Params.menuPageRef }} {{- $isCrosslink = true }} {{- $url = .Params.menuPageRef }} @@ -180,13 +179,6 @@ {{- else if .Params.menuUrl }} {{- $isCrosslink = true }} {{- $url = .Params.menuUrl | relLangURL }} - {{- $u := urls.Parse $url }} - {{- if $u.IsAbs }} - {{- $target = "_blank" }} - {{- if isset site.Params "externallinktarget" }} - {{- $target = site.Params.externalLinkTarget }} - {{- end }} - {{- end }} {{- end }} {{- $pre := partial "menu-pre.html" . }} {{- $post := partial "menu-post.html" . }} @@ -200,7 +192,21 @@ {{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
  • {{- if $isCollapsible }}{{ end }} - {{- if $url }}{{ else }}{{ end }} + {{- if $url }} + {{- $attributes := partial "_relearn/linkAttributes.gotmpl" (dict "url" $url "page" $currentNode "attributes" (dict "class" "padding")) -}} + + {{- else -}} + + {{- end }} {{- $pre }}{{ $title }}{{ $post }} {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}
  • {{- else if $url }} {{- end }} @@ -315,14 +335,6 @@ {{- end }} {{- $title := partial "_relearn/menuTitle.gotmpl" (dict "page" $currentNode "menu" .) }} {{- $url := partial "_relearn/menuPermalink.gotmpl" (dict "page" $currentNode "menu" .) }} - {{- $target := "" }} - {{- $u := urls.Parse $url }} - {{- if $u.IsAbs }} - {{- $target = "_blank" }} - {{- if isset site.Params "externallinktarget" }} - {{- $target = site.Params.externalLinkTarget }} - {{- end }} - {{- end }} {{- $pre := .Pre }} {{- $post := .Post }} {{- with $entryObject }} @@ -339,7 +351,21 @@ {{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
  • {{- if $isCollapsible }}{{ end }} - {{- if $url }}{{ else }}{{ end }} + {{- if $url }} + {{- $attributes := partial "_relearn/linkAttributes.gotmpl" (dict "url" $url "page" $currentNode "attributes" (dict "class" "padding")) -}} + + {{- else -}} + + {{- end }} {{- $pre }}{{ $title }}{{ $post }} {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}
  • {{- else if $url }}
  • - {{- if $url }}{{ else }}{{ end }} + {{- if $url }} + {{- $attributes := partial "_relearn/linkAttributes.gotmpl" (dict "url" $url "page" $currentNode "attributes" (dict "class" "padding")) -}} + + {{- else -}} + + {{- end }} {{- $pre }}{{ $title }}{{ $post }} {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}
  • {{- end }} diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index da0020e8be..117a9fd796 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.3.2+83860202296af0be408eba2a8145c8325403ce04 \ No newline at end of file +7.3.2+72099590d4409d0086ea4b9f6f3188e6847028e6 \ No newline at end of file