From 14c19bb13cecd2d3e72f5f53ad2b03f71dfcef81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 5 Feb 2025 08:33:02 +0100 Subject: [PATCH] menu: allow menuPageRef, menu.pageRef and sidebarmenus.pageRef to be decorated URLs #1008 meaning: having a query string and fragments --- docs/config/_default/hugo.toml | 63 ++++++++-- docs/config/_default/params.toml | 8 +- .../authoring/frontmatter/menus/_index.en.md | 2 +- .../authoring/frontmatter/menus/_index.pir.md | 2 +- docs/content/development/_index.en.md | 8 ++ docs/content/development/_index.pir.md | 8 ++ layouts/alias.html | 4 +- .../partials/_relearn/decoratedLink.gotmpl | 57 +++++++++ layouts/partials/_relearn/linkPage.gotmpl | 48 ++++++++ layouts/partials/_relearn/menuPage.gotmpl | 5 + .../partials/_relearn/menuPermalink.gotmpl | 25 ++++ layouts/partials/_relearn/menuTitle.gotmpl | 10 ++ layouts/partials/_relearn/refPage.gotmpl | 11 ++ .../partials/_relearn/urlErrorReport.gotmpl | 19 +-- layouts/partials/menu.html | 91 ++++++++------ layouts/partials/menupermalink.gotmpl | 25 ---- layouts/partials/menutitle.gotmpl | 12 -- layouts/partials/meta.html | 12 +- layouts/partials/shortcodes/link.html | 111 +----------------- layouts/partials/version.txt | 2 +- 20 files changed, 311 insertions(+), 212 deletions(-) create mode 100644 layouts/partials/_relearn/decoratedLink.gotmpl create mode 100644 layouts/partials/_relearn/linkPage.gotmpl create mode 100644 layouts/partials/_relearn/menuPage.gotmpl create mode 100644 layouts/partials/_relearn/menuPermalink.gotmpl create mode 100644 layouts/partials/_relearn/menuTitle.gotmpl create mode 100644 layouts/partials/_relearn/refPage.gotmpl delete mode 100644 layouts/partials/menupermalink.gotmpl delete mode 100644 layouts/partials/menutitle.gotmpl diff --git a/docs/config/_default/hugo.toml b/docs/config/_default/hugo.toml index aba7b027fc..d0a8f03e5c 100644 --- a/docs/config/_default/hugo.toml +++ b/docs/config/_default/hugo.toml @@ -111,29 +111,52 @@ summaryLength = 10 name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 - [[languages.en.menu.shortcuts]] name = 'Showcases' pageRef = '/showcase' weight = 20 - [[languages.en.menu.shortcuts]] name = 'Credits' pageRef = '/more/credits' weight = 30 - [[languages.en.menu.shortcuts]] pre = ' ' name = 'Tags' pageRef = '/tags' weight = 40 - [[languages.en.menu.shortcuts]] pre = ' ' name = 'Categories' pageRef = '/categories' weight = 50 + [[languages.en.menu.devshortcuts]] + identifier = 'devshortcuts' + name = 'Dev Shortcuts' + [[languages.en.menu.devshortcuts]] + parent = 'devshortcuts' + pre = ' ' + name = 'Hugo' + url = 'https://gohugo.io/documentation/' + [[languages.en.menu.devshortcuts]] + parent = 'devshortcuts' + pre = ' ' + identifier = 'theme' + name = 'Theme' + [[languages.en.menu.devshortcuts.params]] + alwaysopen = true + [[languages.en.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + identifier = 'configoptions' + pageRef = 'configuration/reference' + [[languages.en.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + identifier = 'frontmatter' + title = 'Front Matter Reference' + pageRef = 'authoring/frontmatter/reference#annotated-front-matter' + # this is ourrr way t' showcase th' multilang settings by # doing autotrrranlat'n of th' english content; we are # lazy and don't supporrt furrrther trrranslations; arrr, @@ -153,35 +176,59 @@ summaryLength = 10 #contentDir = 'content/pir' [languages.pir.params] landingPageName = ' Arrr! Home' + errorignore = ['.*'] [[languages.pir.menu.shortcuts]] pre = ' ' name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 - [[languages.pir.menu.shortcuts]] pre = ' ' name = 'Showcases' pageRef = '/showcase' weight = 20 - [[languages.pir.menu.shortcuts]] name = 'Crrredits' pageRef = '/more/credits' weight = 30 - [[languages.pir.menu.shortcuts]] name = 'Arrr! Tags' pageRef = '/tags' weight = 40 - [[languages.pir.menu.shortcuts]] pre = ' ' name = 'Categorrries' pageRef = '/categories' weight = 50 + [[languages.pir.menu.devshortcuts]] + identifier = 'devshortcuts' + name = 'Dev Shortcuts' + [[languages.pir.menu.devshortcuts]] + parent = 'devshortcuts' + pre = ' ' + name = "Cap'n Hugo" + url = 'https://gohugo.io/documentation/' + [[languages.pir.menu.devshortcuts]] + parent = 'devshortcuts' + pre = ' ' + identifier = 'theme' + name = "Th' Theme" + [[languages.pir.menu.devshortcuts.params]] + alwaysopen = true + [[languages.pir.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + identifier = 'configoptions' + pageRef = 'configuration/reference' + [[languages.pir.menu.devshortcuts]] + parent = 'theme' + pre = ' ' + identifier = 'frontmatter' + title = 'Front Matter Reference' + pageRef = 'authoring/frontmatter/reference#annotated-front-matter' + # 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 [module] diff --git a/docs/config/_default/params.toml b/docs/config/_default/params.toml index e8575a4a4a..e62111ad55 100644 --- a/docs/config/_default/params.toml +++ b/docs/config/_default/params.toml @@ -435,7 +435,7 @@ highlightWrap = true # warning is printed. If set to `error` an error message is printed and the build # is aborted. # This can be overridden in the page's frontmatter. -include.errorlevel = 'error' +include.errorlevel = 'warning' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Images @@ -450,7 +450,7 @@ include.errorlevel = 'error' # aborted. # Please note that this can not resolve files inside of your `static` directory. # This can be overridden in the page's frontmatter. -image.errorlevel = 'error' +image.errorlevel = 'warning' # Image effects. # See the documentation for how you can even add your own arbitrary effects to @@ -498,7 +498,7 @@ disableExplicitIndexURLs = false # Please note that with Hugo < 0.123.0 + `uglyURLs=true` this can lead to false # negatives. # This can be overridden in the page's frontmatter. -link.errorlevel = 'error' +link.errorlevel = 'warning' # How to open external links. # Default: '_blank' @@ -602,4 +602,4 @@ customOpenapiURL = '' # 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js' # aborted. # Please note that this can not resolve files inside of your `static` directory. # This can be overridden in the page's frontmatter. -openapi.errorlevel = 'error' +openapi.errorlevel = 'warning' diff --git a/docs/content/authoring/frontmatter/menus/_index.en.md b/docs/content/authoring/frontmatter/menus/_index.en.md index 6d7308f119..b5f975d329 100644 --- a/docs/content/authoring/frontmatter/menus/_index.en.md +++ b/docs/content/authoring/frontmatter/menus/_index.en.md @@ -2,5 +2,5 @@ description = "Setting the behavior of the menus" title = "Menus" weight = 2 -menuPageRef = '/configuration/sidebar/menus' +menuPageRef = '/configuration/sidebar/menus#expand-state-of-submenus' +++ diff --git a/docs/content/authoring/frontmatter/menus/_index.pir.md b/docs/content/authoring/frontmatter/menus/_index.pir.md index 6d7308f119..b5f975d329 100644 --- a/docs/content/authoring/frontmatter/menus/_index.pir.md +++ b/docs/content/authoring/frontmatter/menus/_index.pir.md @@ -2,5 +2,5 @@ description = "Setting the behavior of the menus" title = "Menus" weight = 2 -menuPageRef = '/configuration/sidebar/menus' +menuPageRef = '/configuration/sidebar/menus#expand-state-of-submenus' +++ diff --git a/docs/content/development/_index.en.md b/docs/content/development/_index.en.md index dbfdc86c1c..c7cbc3d3db 100644 --- a/docs/content/development/_index.en.md +++ b/docs/content/development/_index.en.md @@ -5,6 +5,14 @@ hidden = true title = "Development" type = "chapter" weight = 5 +[[cascade]] + [cascade.params] + [[cascade.params.sidebarmenus]] + identifier = 'blog' + type = 'page' + [[cascade.params.sidebarmenus]] + identifier = 'devshortcuts' + type = 'menu' +++ This chapter contains information only needed for development and maintaining the theme. diff --git a/docs/content/development/_index.pir.md b/docs/content/development/_index.pir.md index 671759580c..c1e2e0c4cd 100644 --- a/docs/content/development/_index.pir.md +++ b/docs/content/development/_index.pir.md @@ -5,5 +5,13 @@ hidden = true title = "Development" type = "chapter" weight = 5 +[[cascade]] + [cascade.params] + [[cascade.params.sidebarmenus]] + identifier = 'blog' + type = 'page' + [[cascade.params.sidebarmenus]] + identifier = 'devshortcuts' + type = 'menu' +++ {{< piratify >}} \ No newline at end of file diff --git a/layouts/alias.html b/layouts/alias.html index 78b59a093a..b68e5af752 100644 --- a/layouts/alias.html +++ b/layouts/alias.html @@ -7,12 +7,12 @@ {{- $url = replace .Permalink site.BaseURL "/" }} {{- end }} {{- $url = replace $url "//" "/" }} - {{- with site.Home.GetPage $url }} + {{- with site.GetPage $url }} {{- /* if defaultContentLanguageInSubdir=false we are ending here for home page of the default language */}} {{- $url = partial "permalink.gotmpl" (dict "to" .) }} {{- else }} {{- $url_alt := replaceRE "^/[^/]*(/.*)" "${1}" $url }} - {{- with site.Home.GetPage $url_alt }} + {{- with site.GetPage $url_alt }} {{- /* if defaultContentLanguageInSubdir=true we are ending here for home page */}} {{- $url = partial "permalink.gotmpl" (dict "to" .) }} {{- else }} diff --git a/layouts/partials/_relearn/decoratedLink.gotmpl b/layouts/partials/_relearn/decoratedLink.gotmpl new file mode 100644 index 0000000000..39a5dedaa6 --- /dev/null +++ b/layouts/partials/_relearn/decoratedLink.gotmpl @@ -0,0 +1,57 @@ +{{- $href := partial "permalink.gotmpl" (dict "to" .linkPage) }} +{{- $silent := .silent | default false }} +{{- $hideFilepath := .hideFilepath | default false }} +{{- $u := urls.Parse .url }} +{{- with $u.RawQuery }} + {{- $href = printf "%s?%s" $href . }} +{{- end }} +{{- with $u.Fragment }} + {{- $href = printf "%s#%s" $href . }} + {{- if not $silent }} + {{- partial "inline/validate-fragment.html" (dict "origPage" $.page "page" $.linkPage "parsedURL" $u "url" $.url "param" $.param "hideFilepath" $hideFilepath) }} + {{- end }} +{{- end }} +{{- return $href }} + +{{- define "partials/inline/validate-fragment.html" }} + {{- /* + Validates the fragment portion of a link destination. + */}} + + {{- /* Initialize. */}} + {{- $errorLevel := .errorLevel }} + {{- $origPage := .origPage }} + {{- $p := .page }} + {{- $url := .url }} + {{- $u := .parsedURL }} + {{- $param := .param }} + {{- $hideFilepath := .hideFilepath }} + + {{- /* Validate. */}} + {{- with $u.Fragment }} + {{- if $p.Fragments.Identifiers.Contains . }} + {{- if gt ($p.Fragments.Identifiers.Count .) 1 }} + {{- $filepath := "[virtual file]" }}{{ with and $origPage $origPage.File $origPage.File.Filename }}{{ $filepath = . }}{{ end }} + {{- $msg := printf "%q: duplicate heading ID %q found" $filepath . }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" $url "page" $origPage "param" $param "msg" $msg) }} + {{- end }} + {{- else }} + {{- /* Determine target path for warning and error message. */}} + {{- $targetPath := "" }} + {{- with $p.File }} + {{- $targetPath = .Path }} + {{- else }} + {{- $targetPath = .Path }} + {{- end }} + {{- $filepath := "[virtual file]" }}{{ with and $origPage $origPage.File $origPage.File.Filename }}{{ $filepath = . }}{{ end }} + {{- $msg := printf "heading ID %q not found" . }} + {{- if not $hideFilepath }} + {{- $msg = printf "%q: %s" $filepath $msg }} + {{- end }} + {{- if or $hideFilepath (ne $origPage $p) }} + {{- $msg = printf "%s in %q" $msg $targetPath }} + {{- end }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" $url "page" $origPage "param" $param "msg" $msg) }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/_relearn/linkPage.gotmpl b/layouts/partials/_relearn/linkPage.gotmpl new file mode 100644 index 0000000000..455d688538 --- /dev/null +++ b/layouts/partials/_relearn/linkPage.gotmpl @@ -0,0 +1,48 @@ +{{- $page := .page }} +{{- $linkPage := "" }} +{{- $u := urls.Parse .url }} +{{- $path := strings.TrimPrefix "./" $u.Path }} +{{- $searchLocal := .searchLocal | default true }} +{{- $searchGlobal := .searchGlobal | default true }} +{{- $searchPage := .searchPage | default true }} +{{- $searchResource := .searchResource | default true }} +{{- if $path }} + {{- with or + (and $searchLocal $searchPage ($page.Page.GetPage $path)) + (and $searchLocal $searchPage ($page.Page.GetPage (strings.TrimRight "/" $path))) + (and $searchGlobal $searchPage (site.GetPage $path)) + (and $searchGlobal $searchPage (site.GetPage (strings.TrimRight "/" $path))) + (and $searchLocal $searchResource ($page.Page.Resources.Get $path)) + (and $searchGlobal $searchResource (resources.Get $path)) + }} + {{- $linkPage = . }} + {{- else }} + {{- /* is it a link into another translation? */}} + {{- if strings.HasPrefix $path "/" }} + {{- range $page.AllTranslations }} + {{- $lang := .Language.Lang }} + {{- $prefix := printf "/%s" $lang }} + {{- $suffix := strings.TrimPrefix $prefix $path | default "/" }} + {{- /* with the second check we check if the prefix was finished; + eg. /pir/index.html vs. /pirate/index.html, were the latter is + an external address outside of this site */}} + {{- if and (strings.HasPrefix $path $prefix) (strings.HasPrefix $suffix "/") }} + {{- with or + (and $searchLocal $searchPage (.GetPage $suffix)) + (and $searchLocal $searchPage (.GetPage (strings.TrimRight "/" $suffix))) + (and $searchGlobal $searchPage (site.GetPage $path)) + (and $searchGlobal $searchPage (site.GetPage (strings.TrimRight "/" $path))) + (and $searchLocal $searchResource (.Resources.Get $suffix)) + (and $searchGlobal $searchResource (resources.Get $suffix)) + }} + {{- $linkPage = . }} + {{- break }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} +{{- else }} + {{- $linkPage = $page.Page }} +{{- end }} +{{- return $linkPage }} \ No newline at end of file diff --git a/layouts/partials/_relearn/menuPage.gotmpl b/layouts/partials/_relearn/menuPage.gotmpl new file mode 100644 index 0000000000..32b44bd420 --- /dev/null +++ b/layouts/partials/_relearn/menuPage.gotmpl @@ -0,0 +1,5 @@ +{{- $linkPage := "" }} +{{- with and . .menu }} + {{- $linkPage = partial "_relearn/refPage.gotmpl" (dict "page" $.page "pageRef" .PageRef "refPage" .Page) }} +{{- end }} +{{- return $linkPage }} \ No newline at end of file diff --git a/layouts/partials/_relearn/menuPermalink.gotmpl b/layouts/partials/_relearn/menuPermalink.gotmpl new file mode 100644 index 0000000000..8fcadb47ea --- /dev/null +++ b/layouts/partials/_relearn/menuPermalink.gotmpl @@ -0,0 +1,25 @@ +{{- $url := "" }} +{{- /* because Hugo can not resolve a pageRef if it contains URL query params or + fragments, we simply don't access the .Page here */}} +{{- with and . .menu }} + {{- if .PageRef }} + {{- $url = .PageRef }} + {{- $linkPage := partial "_relearn/refPage.gotmpl" (dict "page" $.page "pageRef" .PageRef "refPage" .Page) }} + {{- if $linkPage }} + {{- $url = partial "_relearn/decoratedLink.gotmpl" (dict "url" .PageRef "page" $.page "linkPage" $linkPage "param" "link" "hideFilepath" true) }} + {{- else }} + {{- $msg := printf "config option 'pageRef' %q for 'menu' entry %q is not a page or a resource" .PageRef (or .KeyName .Identifier .Name .Title) }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .PageRef "page" $.page "param" "link" "msg" $msg) }} + {{- end }} + {{- else if .URL }} + {{- $url = .URL | relLangURL }} + {{- $u := urls.Parse $url }} + {{- if $u.IsAbs }} + {{- partialCached "_relearn/urlExists.gotmpl" (dict "url" $url "page" $.page "type" "menu link") $u.String }} + {{- else }} + {{- $msg := printf "config option 'url' %q for 'menu' entry %q is a local URL; if it references a page or a resource use 'pageRef' instead" .URL (or .KeyName .Identifier .Name .Title) }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .URL "page" $.page "param" "link" "msg" $msg) }} + {{- end }} + {{- end }} +{{- end }} +{{- return $url }} \ No newline at end of file diff --git a/layouts/partials/_relearn/menuTitle.gotmpl b/layouts/partials/_relearn/menuTitle.gotmpl new file mode 100644 index 0000000000..ddf8c44ac1 --- /dev/null +++ b/layouts/partials/_relearn/menuTitle.gotmpl @@ -0,0 +1,10 @@ +{{- $title := "" }} +{{- with and . .menu }} + {{- $pagetitle := "" }} + {{- $menuPage := partial "_relearn/menuPage.gotmpl" (dict "page" $.page "menu" .) }} + {{- with $menuPage }} + {{- $pagetitle = or .LinkTitle .Title }} + {{- end }} + {{- $title = or .Title $pagetitle (.Name | safeHTML) (.Identifier | safeHTML) }} +{{- end }} +{{- return $title }} \ No newline at end of file diff --git a/layouts/partials/_relearn/refPage.gotmpl b/layouts/partials/_relearn/refPage.gotmpl new file mode 100644 index 0000000000..e4fe52a1c8 --- /dev/null +++ b/layouts/partials/_relearn/refPage.gotmpl @@ -0,0 +1,11 @@ +{{- $linkPage := "" }} +{{- /* because Hugo can not resolve a pageRef if it contains URL query params or + fragments, we do it ourself if we detect such a case */}} +{{- with .refPage }} + {{- $linkPage = . }} +{{- else }} + {{- with .pageRef }} + {{- $linkPage = partial "_relearn/linkPage.gotmpl" (dict "url" . "page" $.page "searchLocal" false) }} + {{- end }} +{{- end }} +{{- return $linkPage }} \ No newline at end of file diff --git a/layouts/partials/_relearn/urlErrorReport.gotmpl b/layouts/partials/_relearn/urlErrorReport.gotmpl index d2b4573067..17bf37bc80 100644 --- a/layouts/partials/_relearn/urlErrorReport.gotmpl +++ b/layouts/partials/_relearn/urlErrorReport.gotmpl @@ -1,19 +1,22 @@ {{- $pageParam := index .page.Params .param }} -{{- $siteParam := index .page.Site.Params .param }} +{{- $siteParam := index site.Params .param }} +{{- $applyErrorIgnore := .applyErrorIgnore | default true }} {{- $errorlevel := or (and $pageParam $pageParam.errorlevel) (and $siteParam $siteParam.errorlevel) }} -{{- $errorignore := slice | append (.page.Params.errorignore | default slice ) | append (.page.Site.Params.errorignore | default slice ) }} -{{- if and (eq $errorlevel "warning") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url)) }} +{{- $errorignore := slice | append (.page.Params.errorignore | default slice ) | append (site.Params.errorignore | default slice ) }} +{{- if and (eq $errorlevel "warning") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url "applyErrorIgnore" $applyErrorIgnore)) }} {{- warnf .msg }} -{{- else if and (eq $errorlevel "error") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url)) }} +{{- else if and (eq $errorlevel "error") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url "applyErrorIgnore" $applyErrorIgnore)) }} {{- errorf .msg }} {{- end }} {{- define "partials/inline/show-error" }} {{- $ret := true }} - {{- range .errorignore }} - {{- if findRE . $.url 1 }} - {{- $ret = false }} - {{- break }} + {{- if .applyErrorIgnore }} + {{- range .errorignore }} + {{- if findRE . $.url 1 }} + {{- $ret = false }} + {{- break }} + {{- end }} {{- end }} {{- end }} {{- return $ret }} diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 76711ca9d6..dc2e350a3e 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -99,12 +99,21 @@ + {{- define "partials/inline/page-tree" }} {{- $currentNode := .currentnode }} {{- $config := .config }} {{- $showvisitedlinks := .showvisitedlinks }}
- {{- with site.Home.GetPage ($config.pageRef | default "") }} + {{- $root := site.Home }} + {{- if $config.pageRef }} + {{- $root = partial "_relearn/refPage.gotmpl" (dict "page" $currentNode "pageRef" $config.pageRef) }} + {{- if not $root }} + {{- $msg := printf "config option 'pageRef' %q for 'sidebarmenus' %q is not a page or a resource" $config.pageRef $config.identifier }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" $config.pageRef "page" $currentNode "param" "link" "msg" $msg) }} + {{- end }} + {{- end }} + {{- with $root }} {{- $entry := . }} {{- $entries := partialCached "_relearn/pages.gotmpl" (dict "page" $entry) $entry.Path }} {{- $title := "" }} @@ -134,8 +143,6 @@ {{- end }}
- {{- else }} - {{- warnf "WARNING: page '%s' not found for sidebar menu '%s'" ($config.pageRef | default "") $config.identifier }} {{- end }} {{- end }} {{- define "partials/inline/page-walker" }} @@ -163,18 +170,18 @@ {{- $url := partial "permalink.gotmpl" (dict "to" .) }} {{- $isCrosslink := false }} {{- $target := "" }} - {{- $errorlevel := or $currentNode.Params.link.errorlevel $currentNode.Site.Params.link.errorlevel }} {{- if .Params.menuPageRef }} - {{- with site.Home.GetPage (.Params.menuPageRef) }} - {{- $url = partial "permalink.gotmpl" (dict "to" .) }} - {{- $isCrosslink = true }} + {{- $isCrosslink = true }} + {{- $url = .Params.menuPageRef }} + {{- $linkPage := partial "_relearn/refPage.gotmpl" (dict "page" . "pageRef" .Params.menuPageRef) }} + {{- if $linkPage }} + {{- $url = partial "_relearn/decoratedLink.gotmpl" (dict "url" .Params.menuPageRef "page" . "linkPage" $linkPage "param" "link" "silent" true) }} {{- end }} {{- else if .Params.menuUrl }} - {{- $url = .Params.menuUrl }} {{- $isCrosslink = true }} + {{- $url = .Params.menuUrl | relLangURL }} {{- $u := urls.Parse $url }} {{- if $u.IsAbs }} - {{- partialCached "_relearn/urlExists.gotmpl" (dict "url" $url "page" $currentNode "type" "menu link") $u.String }} {{- $target = "_blank" }} {{- if isset site.Params "externallinktarget" }} {{- $target = site.Params.externalLinkTarget }} @@ -193,7 +200,7 @@ {{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
  • {{- if $isCollapsible }}{{ end }} - {{- if $url }}{{ else }}{{ end }} + {{- if $url }}{{ else }}{{ end }} {{- $pre }}{{ $title }}{{ $post }} {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}
  • {{- else if $url }} {{- end }} {{- end }} {{- end }} + {{- define "partials/inline/menu-tree" }} {{- $currentNode := .currentnode }} {{- $config := .config }} {{- $showvisitedlinks := .showvisitedlinks }} {{- with index site.Menus $config.identifier }}
    - {{- $entry := "" }} + {{- $topLevelMenu := "" }} + {{- $topLevelPage := "" }} {{- $entries := . }} - {{- if eq (len $entries) 1 }} - {{- with index $entries 0 }} - {{- if not (partial "menupermalink.gotmpl" (dict "page" $currentNode "menu" .)) }} - {{- /* because in Hugo menus can not have parameter but menu entries can, - we can flag a single top level menu entry as a container; this container - entry carrys just meta information and parameter, uses its children - to build the "real" menu, and has no own `url` or `pageRef` */}} - {{- $entry = . }} - {{- $entries = .Children }} - {{- end }} + {{- with and (eq (len $entries) 1) (index $entries 0) }} + {{- if and (not .PageRef) (not .URL) }} + {{- /* because in Hugo menus can not have parameter but menu entries can, + we can flag a single top level menu entry as a container; this container + entry carrys just meta information and parameter, uses its children + to build the "real" menu, and has no own `url` or `pageRef` */}} + {{- $topLevelMenu = . }} + {{- $topLevelPage = partial "_relearn/menuPage.gotmpl" (dict "page" $currentNode "menu" $topLevelMenu) }} + {{- $entries = .Children }} {{- end }} {{- end }} {{- $title := "" }} {{- if not ($config.disableTitle | default false) }} - {{- if $entry }} - {{- $title = partial "menutitle.gotmpl" $entry }} + {{- if $topLevelMenu }} + {{- $title = partial "_relearn/menuTitle.gotmpl" (dict "page" $currentNode "menu" $topLevelMenu) }} {{- else if eq $config.identifier "shortcuts" }} {{- if not site.Params.DisableShortcutsTitle }} {{- $title = T (print $config.identifier "-menuTitle") }} @@ -257,16 +265,17 @@ {{- $classes = "enlarge morespace " }} {{- end }}
    {{- else }} {{ if ne $config.identifier "shortcuts" }} - {{- warnf "WARNING: menu '%s' not found for sidebar menu '%s'" $config.identifier $config.identifier }} + {{- $msg := printf "config option 'identifier' for 'sidebarmenus' %q is not a menu" $config.identifier }} + {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" $config.pageRef "page" $currentNode "param" "link" "msg" $msg "applyErrorIgnore" false) }} {{- end }} {{- end }} {{- end }} @@ -289,20 +299,22 @@ {{- $root := .root }} {{- with .menu }} {{- $isActive := $isSelf }} - {{- $entry := . }} + {{- $entryMenu := . }} + {{- $entryPage := partial "_relearn/menuPage.gotmpl" (dict "page" $currentNode "menu" $entryMenu) }} {{- $entries := .Children }} {{- $hasVisibleChildren := false }} {{- range $entries }} - {{- $isSubSelf := eq .Page $currentNode }} + {{- $entriesPage := partial "_relearn/menuPage.gotmpl" (dict "page" $currentNode "menu" .) }} + {{- $isSubSelf := eq $entriesPage $currentNode }} {{- $isSubAncestor := and (not $isSubSelf) ($currentNode.HasMenuCurrent .Menu .) }} - {{- $isSubHidden := or (.Params.hidden) (eq (partial "menutitle.gotmpl" .) "") }} + {{- $isSubHidden := or (.Params.hidden) (eq (partial "_relearn/menuTitle.gotmpl" (dict "page" $currentNode "menu" .)) "") }} {{- if or $isSubAncestor $isSubSelf (not $isSubHidden) }} {{- $hasVisibleChildren = true }} {{- break }} {{- end }} {{- end }} - {{- $title := partial "menutitle.gotmpl" . }} - {{- $url := partial "menupermalink.gotmpl" (dict "page" $currentNode "menu" .) }} + {{- $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 }} @@ -313,7 +325,7 @@ {{- end }} {{- $pre := .Pre }} {{- $post := .Post }} - {{- with .Page }} + {{- with $entryPage }} {{- $pre = or $pre (partial "menu-pre.html" .) }} {{- $post = or $post (partial "menu-post.html" .) }} {{- end }} @@ -323,7 +335,7 @@ {{- if and (not $url) (not $isCollapsible) }} {{- $currentAlwaysopen = true }} {{- end }} - {{- $entryId := md5 (print .) }} + {{- $entryId := md5 (print $entryMenu) }} {{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
  • {{- if $isCollapsible }}{{ end }} @@ -332,13 +344,14 @@ {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}