mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
menu: support for external links #148
This commit is contained in:
parent
40a55a3e52
commit
10fb679d67
9 changed files with 93 additions and 17 deletions
|
@ -2,8 +2,5 @@
|
||||||
description = "Setting the behavior of the menus"
|
description = "Setting the behavior of the menus"
|
||||||
title = "Menus"
|
title = "Menus"
|
||||||
weight = 2
|
weight = 2
|
||||||
|
menuPageRef = '/configuration/sidebar/menus'
|
||||||
+++
|
+++
|
||||||
|
|
||||||
The theme can build menu trees from [the structure of your page files](authoring/structure) or from [Hugo's build in menu feature](https://gohugo.io/content-management/menus/).
|
|
||||||
|
|
||||||
To keep all documentation for menus together, you can [find it in the configureation section](configuration/sidebar/menus).
|
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
description = "Setting the behavior of the menus"
|
description = "Setting the behavior of the menus"
|
||||||
title = "Menus"
|
title = "Menus"
|
||||||
weight = 2
|
weight = 2
|
||||||
|
menuPageRef = '/configuration/sidebar/menus'
|
||||||
+++
|
+++
|
||||||
{{< piratify >}}
|
|
|
@ -1,7 +1,7 @@
|
||||||
+++
|
+++
|
||||||
categories = ["howto"]
|
categories = ["howto"]
|
||||||
description = "Configure all things menus"
|
description = "Configure all things menus"
|
||||||
frontmatter = ["alwaysopen", "collapsibleMenu", "linkTitle", "menuPost", "menuPre", "ordersectionsby", "sidebarmenus"]
|
frontmatter = ["alwaysopen", "collapsibleMenu", "linkTitle", "menuPageRef", "menuPost", "menuPre", "menuUrl", "ordersectionsby", "sidebarmenus"]
|
||||||
options = ["alwaysopen", "collapsibleMenu", "disableShortcutsTitle", "ordersectionsby", "sidebarmenus"]
|
options = ["alwaysopen", "collapsibleMenu", "disableShortcutsTitle", "ordersectionsby", "sidebarmenus"]
|
||||||
title = "Menus"
|
title = "Menus"
|
||||||
weight = 4
|
weight = 4
|
||||||
|
@ -261,6 +261,42 @@ title = 'Documentation'
|
||||||
]
|
]
|
||||||
{{< /multiconfig >}}
|
{{< /multiconfig >}}
|
||||||
|
|
||||||
|
## Displaying Arbitrary Links in a Page Menu
|
||||||
|
|
||||||
|
You may have the need to add arbitrary links at some point in your menu that are initially not backed by a page. These are called crosslinks.
|
||||||
|
|
||||||
|
Assume the following structure
|
||||||
|
|
||||||
|
````plaintext
|
||||||
|
content
|
||||||
|
├── reference
|
||||||
|
│ ├── ref-a.md
|
||||||
|
│ ├── ref-b.md
|
||||||
|
│ ├── ref-c.md
|
||||||
|
│ └── _index_.md
|
||||||
|
├── topic-blue.md
|
||||||
|
├── topic-red.md
|
||||||
|
├── topic-yellow.md
|
||||||
|
└── _index_.md
|
||||||
|
````
|
||||||
|
|
||||||
|
You now want to include `ref-b` as separate entry after `topic-green` in your menu.
|
||||||
|
|
||||||
|
For that create a new page with the following front matter
|
||||||
|
|
||||||
|
{{< multiconfig fm=true file="content/topic-green.md" >}}
|
||||||
|
title = 'Topic Green'
|
||||||
|
menuPageRef = '/reference/ref-b'
|
||||||
|
{{< /multiconfig >}}
|
||||||
|
|
||||||
|
If you want to link to an external page instead, you can use `menuUrl` instead of `menuPageRef`.
|
||||||
|
|
||||||
|
Pages defining a crosslink are never part of the arrow navigation and are skipped instead.
|
||||||
|
|
||||||
|
So with the above example and alphabetical sorting of the menu entries, pressing {{% button style="transparent" icon="chevron-right" %}}{{% /button %}} on `topic-blue` will skip the newly added `topic-green` and instead will load `topic-red`.
|
||||||
|
|
||||||
|
Having sub pages below a page that defines a crosslink is undefined.
|
||||||
|
|
||||||
## Displaying Pages Exclusively in a Hugo Menu
|
## Displaying Pages Exclusively in a Hugo Menu
|
||||||
|
|
||||||
Sometimes you want to hide pages from the page menu but instead want to show them in a Hugo menu. For that you have two choices
|
Sometimes you want to hide pages from the page menu but instead want to show them in a Hugo menu. For that you have two choices
|
||||||
|
|
|
@ -23,3 +23,7 @@ weight = -1
|
||||||
- apply the usual parameter `alwaysopen`, `collapsibleMenu`, etc. for all menu types
|
- apply the usual parameter `alwaysopen`, `collapsibleMenu`, etc. for all menu types
|
||||||
|
|
||||||
You don't need to change anything in your existing installation as the old configuration is used as a default.
|
You don't need to change anything in your existing installation as the old configuration is used as a default.
|
||||||
|
|
||||||
|
### New
|
||||||
|
|
||||||
|
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Menus created by your page structure are now able to [contain arbitrary links](configuration/sidebar/menus#displaying-arbitrary-links-in-a-page-menu) inserted into the structure using the `menuUrl` or `menuPageRef` front matter.
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
{{- range $siblings }}
|
{{- range $siblings }}
|
||||||
{{- if eq . $currentNode }}
|
{{- if eq . $currentNode }}
|
||||||
{{- $currentFound = true }}
|
{{- $currentFound = true }}
|
||||||
{{- else if $currentFound }}
|
{{- else if and $currentFound (not (or (eq .Title "") .Params.hidden .Params.menuUrl .Params.menuPageRef)) }}
|
||||||
{{- $nextSibling = . }}
|
{{- $nextSibling = . }}
|
||||||
{{- break }}
|
{{- break }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
|
|
||||||
{{- define "partials/inline/leftmost_descendant" }}
|
{{- define "partials/inline/leftmost_descendant" }}
|
||||||
{{- $leftmostVisible := "" }}
|
{{- $leftmostVisible := "" }}
|
||||||
{{- if not (or (.Params.hidden) (eq .Title "")) }}
|
{{- if not (or (eq .Title "") .Params.hidden .Params.menuUrl .Params.menuPageRef) }}
|
||||||
{{- if .RelPermalink }}
|
{{- if .RelPermalink }}
|
||||||
{{- $leftmostVisible = . }}
|
{{- $leftmostVisible = . }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
{{- range $siblings }}
|
{{- range $siblings }}
|
||||||
{{- if eq . $currentNode }}
|
{{- if eq . $currentNode }}
|
||||||
{{- break }}
|
{{- break }}
|
||||||
{{- else if not (or (.Params.hidden) (eq .Title "")) }}
|
{{- else if not (or (eq .Title "") .Params.hidden .Params.menuUrl .Params.menuPageRef) }}
|
||||||
{{- $previousSibling = . }}
|
{{- $previousSibling = . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
{{- $rightmostVisible := . }}
|
{{- $rightmostVisible := . }}
|
||||||
{{- $pages := (partialCached "_relearn/pages.gotmpl" (dict "page" $rightmostVisible) $rightmostVisible.Path) | collections.Reverse }}
|
{{- $pages := (partialCached "_relearn/pages.gotmpl" (dict "page" $rightmostVisible) $rightmostVisible.Path) | collections.Reverse }}
|
||||||
{{- range $pages }}
|
{{- range $pages }}
|
||||||
{{- if not (or (.Params.hidden) (eq .Title "")) }}
|
{{- if not (or (eq .Title "") .Params.hidden .Params.menuUrl .Params.menuPageRef) }}
|
||||||
{{- with partial "inline/rightmost_descendant" . }}
|
{{- with partial "inline/rightmost_descendant" . }}
|
||||||
{{- if .RelPermalink }}
|
{{- if .RelPermalink }}
|
||||||
{{- $rightmostVisible = . }}
|
{{- $rightmostVisible = . }}
|
||||||
|
|
|
@ -161,9 +161,27 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
{{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }}
|
||||||
{{- $url := partial "permalink.gotmpl" (dict "to" .) }}
|
{{- $url := partial "permalink.gotmpl" (dict "to" .) }}
|
||||||
|
{{- $isCrosslink := false }}
|
||||||
|
{{- $target := "" }}
|
||||||
|
{{- if .Params.menuPageRef }}
|
||||||
|
{{- with site.Home.GetPage (.Params.menuPageRef) }}
|
||||||
|
{{- $url = partial "permalink.gotmpl" (dict "to" .) }}
|
||||||
|
{{- $isCrosslink = true }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if .Params.menuUrl }}
|
||||||
|
{{- $url = .Params.menuUrl }}
|
||||||
|
{{- $isCrosslink = true }}
|
||||||
|
{{- $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" . }}
|
{{- $pre := partial "menu-pre.html" . }}
|
||||||
{{- $post := partial "menu-post.html" . }}
|
{{- $post := partial "menu-post.html" . }}
|
||||||
{{- if $hasVisibleChildren }}
|
{{- if and $hasVisibleChildren (not $isCrosslink) }}
|
||||||
{{- $isCollapsible := .Params.collapsibleMenu | default site.Params.collapsibleMenu }}
|
{{- $isCollapsible := .Params.collapsibleMenu | default site.Params.collapsibleMenu }}
|
||||||
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
|
||||||
{{- if and (not $url) (not $isCollapsible) }}
|
{{- if and (not $url) (not $isCollapsible) }}
|
||||||
|
@ -173,7 +191,7 @@
|
||||||
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
||||||
<li class="{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">
|
<li class="{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">
|
||||||
{{- if $isCollapsible }}<input type="checkbox" id="R-section-{{ $entryId }}" aria-controls="R-subsections-{{ $entryId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $entryId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}
|
{{- if $isCollapsible }}<input type="checkbox" id="R-section-{{ $entryId }}" aria-controls="R-subsections-{{ $entryId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $entryId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}
|
||||||
{{- if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
{{- if $url }}<a class="padding" href="{{ $url }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ else }}<span class="padding">{{ end }}
|
||||||
{{- $pre }}{{ $title }}{{ $post }}
|
{{- $pre }}{{ $title }}{{ $post }}
|
||||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $entryId }}" class="collapsible-menu">
|
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $entryId }}" class="collapsible-menu">
|
||||||
{{- $defaultAlwaysopen := site.Params.alwaysopen | default true }}
|
{{- $defaultAlwaysopen := site.Params.alwaysopen | default true }}
|
||||||
|
@ -190,8 +208,8 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}</ul></li>
|
{{- end }}</ul></li>
|
||||||
{{- else if $url }}
|
{{- else if $url }}
|
||||||
<li class="{{if $isActive }}active {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}" data-nav-id="{{ $url }}">
|
<li class="{{if $isActive }}active {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}{{if $isCrosslink }}crosslink {{end}}" data-nav-id="{{ $url }}">
|
||||||
{{- if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
{{- if $url }}<a class="padding" href="{{ $url }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ else }}<span class="padding">{{ end }}
|
||||||
{{- $pre }}{{ $title }}{{ $post }}
|
{{- $pre }}{{ $title }}{{ $post }}
|
||||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -283,6 +301,14 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $title := partial "menutitle.gotmpl" . }}
|
{{- $title := partial "menutitle.gotmpl" . }}
|
||||||
{{- $url := partial "menupermalink.gotmpl" . }}
|
{{- $url := partial "menupermalink.gotmpl" . }}
|
||||||
|
{{- $target := "" }}
|
||||||
|
{{- $u := urls.Parse $url }}
|
||||||
|
{{- if $u.IsAbs }}
|
||||||
|
{{- $target = "_blank" }}
|
||||||
|
{{- if isset site.Params "externallinktarget" }}
|
||||||
|
{{- $target = site.Params.externalLinkTarget }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
{{- $pre := .Pre }}
|
{{- $pre := .Pre }}
|
||||||
{{- $post := .Post }}
|
{{- $post := .Post }}
|
||||||
{{- with .Page }}
|
{{- with .Page }}
|
||||||
|
@ -299,7 +325,7 @@
|
||||||
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
{{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
|
||||||
<li class="{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">
|
<li class="{{if $isActive }}active {{end}}{{if (or $isSelf $isAncestor) }}parent {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}{{if $currentAlwaysopen}}alwaysopen {{end}}" data-nav-id="{{ $url }}">
|
||||||
{{- if $isCollapsible }}<input type="checkbox" id="R-section-{{ $entryId }}" aria-controls="R-subsections-{{ $entryId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $entryId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}
|
{{- if $isCollapsible }}<input type="checkbox" id="R-section-{{ $entryId }}" aria-controls="R-subsections-{{ $entryId }}"{{ if $isOpen }} checked{{ end }}><label for="R-section-{{ $entryId }}"><i class="fa-fw fas fa-chevron-down"></i><i class="fa-fw fas fa-chevron-right"></i><span class="a11y-only">{{ T "Submenu" $title }}</span></label>{{ end }}
|
||||||
{{- if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
{{- if $url }}<a class="padding" href="{{ $url }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ else }}<span class="padding">{{ end }}
|
||||||
{{- $pre }}{{ $title }}{{ $post }}
|
{{- $pre }}{{ $title }}{{ $post }}
|
||||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $entryId }}" class="collapsible-menu">
|
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}<ul id="R-subsections-{{ $entryId }}" class="collapsible-menu">
|
||||||
{{- $defaultAlwaysopen := site.Params.alwaysopen | default true }}
|
{{- $defaultAlwaysopen := site.Params.alwaysopen | default true }}
|
||||||
|
@ -317,7 +343,7 @@
|
||||||
{{- end }}</ul></li>
|
{{- end }}</ul></li>
|
||||||
{{- else if $url }}
|
{{- else if $url }}
|
||||||
<li class="{{if $isActive }}active {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}" data-nav-id="{{ $url }}">
|
<li class="{{if $isActive }}active {{end}}{{if $isHidden }}hidden {{end}}{{if not $url }}headless {{end}}" data-nav-id="{{ $url }}">
|
||||||
{{- if $url }}<a class="padding" href="{{ $url }}">{{ else }}<span class="padding">{{ end }}
|
{{- if $url }}<a class="padding" href="{{ $url }}"{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ else }}<span class="padding">{{ end }}
|
||||||
{{- $pre }}{{ $title }}{{ $post }}
|
{{- $pre }}{{ $title }}{{ $post }}
|
||||||
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
{{- if $url }}{{ if $showvisitedlinks }}<i class="fa-fw fas fa-check read-icon"></i>{{ end }}</a>{{ else }}</span>{{ end }}</li>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -14,6 +14,19 @@
|
||||||
{{- if not (and $title .RelPermalink (or (ne .Site.Params.disableSeoHiddenPages true) (not (partialCached "_relearn/pageIsHiddenSelfOrAncestor.gotmpl" (dict "page" . "to" .Site.Home) .Path .Site.Home.Path) ) ) ) }}
|
{{- if not (and $title .RelPermalink (or (ne .Site.Params.disableSeoHiddenPages true) (not (partialCached "_relearn/pageIsHiddenSelfOrAncestor.gotmpl" (dict "page" . "to" .Site.Home) .Path .Site.Home.Path) ) ) ) }}
|
||||||
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">
|
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- $url := "" }}
|
||||||
|
{{- if .Params.menuPageRef }}
|
||||||
|
{{- with site.Home.GetPage (.Params.menuPageRef) }}
|
||||||
|
{{- $url = partial "permalink.gotmpl" (dict "to" .) }}
|
||||||
|
{{- else }}
|
||||||
|
{{- warnf "%q: WARNING: page '%s' not found for 'menuPageRef' parameter" .File.Filename .Params.menuPageRef }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if .Params.menuUrl }}
|
||||||
|
{{- $url = .Params.menuUrl }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if $url }}
|
||||||
|
<meta http-equiv="refresh" content="0; url={{ $url }}">
|
||||||
|
{{- end }}
|
||||||
<meta name="description" content="{{ with trim (or .Description .Summary | plainify | htmlUnescape) "\n\r\t " }}{{ . }}{{ end }}">
|
<meta name="description" content="{{ with trim (or .Description .Summary | plainify | htmlUnescape) "\n\r\t " }}{{ . }}{{ end }}">
|
||||||
{{- $authorName := partialCached "_relearn/authorName.gotmpl" . }}
|
{{- $authorName := partialCached "_relearn/authorName.gotmpl" . }}
|
||||||
<meta name="author" content="{{ $authorName }}">
|
<meta name="author" content="{{ $authorName }}">
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
7.0.1+9797e071ae2d359be854f02d76ac3a9e8cd22f72
|
7.0.1+40a55a3e52be6798651fabb67c3fa4b8dc26d6e6
|
Loading…
Reference in a new issue