Merge branch 'main' of https://github.com/imfing/hextra
This commit is contained in:
@@ -21,10 +21,12 @@
|
||||
{{- end -}}
|
||||
|
||||
<aside class="hextra-sidebar-container hx:flex hx:flex-col hx:print:hidden hx:md:top-16 hx:md:shrink-0 hx:md:w-64 hx:md:self-start hx:max-md:[transform:translate3d(0,-100%,0)] {{ $sidebarClass }}">
|
||||
<!-- Search bar on small screen -->
|
||||
<div class="hx:px-4 hx:pt-4 hx:md:hidden">
|
||||
{{ partial "search.html" }}
|
||||
</div>
|
||||
{{- if (site.Params.search.enable | default true) -}}
|
||||
<!-- Search bar on small screen -->
|
||||
<div class="hx:px-4 hx:pt-4 hx:md:hidden">
|
||||
{{ partial "search.html" (dict "location" "sidebar") }}
|
||||
</div>
|
||||
{{- end -}}
|
||||
<div class="hextra-scrollbar hx:overflow-y-auto hx:overflow-x-hidden hx:p-4 hx:grow hx:md:h-[calc(100vh-var(--navbar-height)-var(--menu-height))]">
|
||||
<ul class="hx:flex hx:flex-col hx:gap-1 hx:md:hidden">
|
||||
<!-- Nav -->
|
||||
@@ -75,38 +77,159 @@
|
||||
{{- $pageURL := .page.RelPermalink -}}
|
||||
{{- $level := .level -}}
|
||||
{{- $toc := .toc | default false -}}
|
||||
{{- $useMainMenu := and (eq $level 0) $toc -}}
|
||||
{{- $mainMenuEntries := slice -}}
|
||||
|
||||
{{- with $items := union .context.RegularPages .context.Sections -}}
|
||||
{{- $items = where $items "Params.sidebar.exclude" "!=" true -}}
|
||||
{{- if eq $level 0 -}}
|
||||
{{- range $items.ByWeight }}
|
||||
{{- if .Params.sidebar.separator -}}
|
||||
<li class="[word-break:break-word] hx:mt-5 hx:mb-2 hx:px-2 hx:py-1.5 hx:text-sm hx:font-semibold hx:text-gray-900 hx:first:mt-0 hx:dark:text-gray-100">
|
||||
<span class="hx:cursor-default">{{ partial "utils/title" . }}</span>
|
||||
</li>
|
||||
{{- else -}}
|
||||
{{- $active := eq $pageURL .RelPermalink -}}
|
||||
{{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }}
|
||||
<li class="{{ if $shouldOpen }}open{{ end }}">
|
||||
{{- $linkTitle := partial "utils/title" . -}}
|
||||
{{- template "sidebar-item-link" dict "context" . "active" $active "title" $linkTitle "link" .RelPermalink -}}
|
||||
{{- if and $toc $active -}}
|
||||
{{- template "sidebar-toc" dict "page" . -}}
|
||||
{{- $items := slice -}}
|
||||
{{- if $useMainMenu -}}
|
||||
{{- range $menuItem := site.Menus.main -}}
|
||||
{{- $menuType := $menuItem.Params.type | default "" -}}
|
||||
{{- $isIconOnly := and $menuItem.Params.icon (ne $menuType "link") -}}
|
||||
{{- /* Keep only navigation links in the mobile sidebar. */ -}}
|
||||
{{- if or (eq $menuType "search") (eq $menuType "theme-toggle") (eq $menuType "language-switch") $isIconOnly -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $menuTitle := or (T $menuItem.Identifier) $menuItem.Name -}}
|
||||
{{- /* Dropdown parents mirror navbar behavior: render a labeled group of child links. */ -}}
|
||||
{{- if $menuItem.HasChildren -}}
|
||||
{{- $childEntries := slice -}}
|
||||
{{- range $childItem := $menuItem.Children -}}
|
||||
{{- $childType := $childItem.Params.type | default "" -}}
|
||||
{{- $childIsIconOnly := and $childItem.Params.icon (ne $childType "link") -}}
|
||||
{{- if or (eq $childType "search") (eq $childType "theme-toggle") (eq $childType "language-switch") $childIsIconOnly -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $childTitle := or (T $childItem.Identifier) $childItem.Name -}}
|
||||
{{- with $childItem.Page -}}
|
||||
{{- if ne .Params.sidebar.exclude true -}}
|
||||
{{- $childEntries = $childEntries | append (dict "title" $childTitle "link" .RelPermalink) -}}
|
||||
{{- end -}}
|
||||
{{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
|
||||
</li>
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $childLink := $childItem.URL -}}
|
||||
{{- with $childItem.PageRef -}}
|
||||
{{- if hasPrefix . "/" -}}
|
||||
{{- $childLink = relLangURL (strings.TrimPrefix "/" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $childLink -}}
|
||||
{{- $childEntries = $childEntries | append (dict "title" $childTitle "link" $childLink) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if gt (len $childEntries) 0 -}}
|
||||
{{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "group" "title" $menuTitle "children" $childEntries) -}}
|
||||
{{- end -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Normalize page-backed entries so we keep nested tree behavior. */ -}}
|
||||
{{- with $menuItem.Page -}}
|
||||
{{- if ne .Params.sidebar.exclude true -}}
|
||||
{{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "page" "item" . "title" $menuTitle) -}}
|
||||
{{- end -}}
|
||||
{{- continue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $link := $menuItem.URL -}}
|
||||
{{- with $menuItem.PageRef -}}
|
||||
{{- if hasPrefix . "/" -}}
|
||||
{{- $link = relLangURL (strings.TrimPrefix "/" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $link -}}
|
||||
{{- $mainMenuEntries = $mainMenuEntries | append (dict "type" "url" "link" $link "title" $menuTitle) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $items = where (union .context.RegularPages .context.Sections) "Params.sidebar.exclude" "!=" true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hasItems := gt (len $items) 0 -}}
|
||||
{{- if $useMainMenu -}}
|
||||
{{- $hasItems = gt (len $mainMenuEntries) 0 -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $hasItems -}}
|
||||
{{- if eq $level 0 -}}
|
||||
{{- if $useMainMenu -}}
|
||||
{{- /* Mixed list: page entries render trees; url entries render leaf links. */ -}}
|
||||
{{- range $entry := $mainMenuEntries -}}
|
||||
{{- if eq (index $entry "type") "page" -}}
|
||||
{{- $item := index $entry "item" -}}
|
||||
{{- if $item.Params.sidebar.separator -}}
|
||||
<li class="[word-break:break-word] hx:mt-5 hx:mb-2 hx:px-2 hx:py-1.5 hx:text-sm hx:font-semibold hx:text-gray-900 hx:first:mt-0 hx:dark:text-gray-100">
|
||||
<span class="hx:cursor-default">{{ index $entry "title" }}</span>
|
||||
</li>
|
||||
{{- else -}}
|
||||
{{- $active := eq (strings.TrimSuffix "/" $pageURL) (strings.TrimSuffix "/" $item.RelPermalink) -}}
|
||||
{{- $shouldOpen := or ($item.Params.sidebar.open) ($item.IsAncestor $page) $active | default true }}
|
||||
<li class="{{ if $shouldOpen }}open{{ end }}">
|
||||
{{- template "sidebar-item-link" dict "context" $item "active" $active "open" $shouldOpen "title" (index $entry "title") "link" $item.RelPermalink -}}
|
||||
{{- if and $toc $active (ne $item.Params.toc false) -}}
|
||||
{{- template "sidebar-toc" dict "page" $item -}}
|
||||
{{- end -}}
|
||||
{{- template "sidebar-tree" dict "context" $item "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- else if eq (index $entry "type") "group" -}}
|
||||
<li class="open">
|
||||
<div class="hextra-sidebar-item hx:group hx:relative hx:flex hx:items-center">
|
||||
<span class="hx:flex hx:grow hx:cursor-default hx:px-2 hx:py-1.5 hx:text-sm hx:font-semibold hx:text-gray-900 hx:dark:text-gray-100">
|
||||
{{- index $entry "title" -}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="hextra-sidebar-children hx:ltr:pr-0 hx:rtl:pl-0 hx:overflow-hidden">
|
||||
<ul class='hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800'>
|
||||
{{- range $child := index $entry "children" -}}
|
||||
{{- $link := index $child "link" -}}
|
||||
{{- $active := eq (strings.TrimSuffix "/" $pageURL) (strings.TrimSuffix "/" $link) -}}
|
||||
<li class="hx:flex hx:flex-col">
|
||||
{{- template "sidebar-item-link" dict "active" $active "open" false "title" (index $child "title") "link" $link -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
{{- else -}}
|
||||
{{- $link := index $entry "link" -}}
|
||||
{{- $active := eq (strings.TrimSuffix "/" $pageURL) (strings.TrimSuffix "/" $link) -}}
|
||||
<li>{{ template "sidebar-item-link" dict "active" $active "open" false "title" (index $entry "title") "link" $link }}</li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- range $items.ByWeight }}
|
||||
{{- if .Params.sidebar.separator -}}
|
||||
<li class="[word-break:break-word] hx:mt-5 hx:mb-2 hx:px-2 hx:py-1.5 hx:text-sm hx:font-semibold hx:text-gray-900 hx:first:mt-0 hx:dark:text-gray-100">
|
||||
<span class="hx:cursor-default">{{ partial "utils/title" . }}</span>
|
||||
</li>
|
||||
{{- else -}}
|
||||
{{- $active := eq $pageURL .RelPermalink -}}
|
||||
{{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }}
|
||||
<li class="{{ if $shouldOpen }}open{{ end }}">
|
||||
{{- $linkTitle := partial "utils/title" . -}}
|
||||
{{- template "sidebar-item-link" dict "context" . "active" $active "open" $shouldOpen "title" $linkTitle "link" .RelPermalink -}}
|
||||
{{- if and $toc $active (ne .Params.toc false) -}}
|
||||
{{- template "sidebar-toc" dict "page" . -}}
|
||||
{{- end -}}
|
||||
{{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
|
||||
</li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
<div class="hx:ltr:pr-0 hx:overflow-hidden">
|
||||
<div class="hextra-sidebar-children hx:ltr:pr-0 hx:rtl:pl-0 hx:overflow-hidden">
|
||||
<ul class='hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800'>
|
||||
{{- range $items.ByWeight }}
|
||||
{{- $active := eq $pageURL .RelPermalink -}}
|
||||
{{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }}
|
||||
{{- $linkTitle := partial "utils/title" . -}}
|
||||
<li class="hx:flex hx:flex-col {{ if $shouldOpen }}open{{ end }}">
|
||||
{{- template "sidebar-item-link" dict "context" . "active" $active "title" $linkTitle "link" .RelPermalink -}}
|
||||
{{- if and $toc $active -}}
|
||||
{{- template "sidebar-item-link" dict "context" . "active" $active "open" $shouldOpen "title" $linkTitle "link" .RelPermalink -}}
|
||||
{{- if and $toc $active (ne .Params.toc false) -}}
|
||||
{{ template "sidebar-toc" dict "page" . }}
|
||||
{{- end }}
|
||||
{{ template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc }}
|
||||
@@ -115,7 +238,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "sidebar-toc" -}}
|
||||
@@ -154,7 +277,7 @@
|
||||
{{- $link = relLangURL (strings.TrimPrefix "/" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
<li>{{ template "sidebar-item-link" dict "active" false "title" $name "link" $link }}</li>
|
||||
<li>{{ template "sidebar-item-link" dict "active" false "open" false "title" $name "link" $link }}</li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -162,27 +285,31 @@
|
||||
{{- define "sidebar-item-link" -}}
|
||||
{{- $external := strings.HasPrefix .link "http" -}}
|
||||
{{- $open := .open | default true -}}
|
||||
<a
|
||||
class="hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
|
||||
{{- if .active }}
|
||||
hextra-sidebar-active-item hx:bg-primary-100 hx:font-semibold hx:text-primary-800 hx:contrast-more:border hx:contrast-more:border-primary-500 hx:dark:bg-primary-400/10 hx:dark:text-primary-600 hx:contrast-more:dark:border-primary-500
|
||||
{{- else }}
|
||||
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50
|
||||
{{- end -}}"
|
||||
href="{{ .link }}"
|
||||
{{ if $external }}target="_blank" rel="noreferrer"{{ end }}
|
||||
>
|
||||
{{- .title -}}
|
||||
{{- with .context }}
|
||||
{{- if or .RegularPages .Sections }}
|
||||
<span class="hextra-sidebar-collapsible-button">
|
||||
{{- template "sidebar-collapsible-button" -}}
|
||||
</span>
|
||||
{{- end }}
|
||||
{{ end -}}
|
||||
</a>
|
||||
{{- $hasChildren := false -}}
|
||||
{{- with .context }}{{ if or .RegularPages .Sections }}{{ $hasChildren = true }}{{ end }}{{ end -}}
|
||||
<div class="hextra-sidebar-item hx:group hx:relative hx:flex hx:items-center" data-active="{{ if .active }}true{{ else }}false{{ end }}">
|
||||
<a
|
||||
class="hx:flex hx:items-center hx:justify-between hx:gap-2 hx:grow hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none]
|
||||
{{- if $hasChildren }} hx:ltr:pr-8 hx:rtl:pl-8{{- end }}
|
||||
hx:hextra-focus-visible-inset
|
||||
{{- if .active }}
|
||||
hextra-sidebar-active-item hx:bg-primary-100 hx:font-semibold hx:text-primary-800 hx:contrast-more:border hx:contrast-more:border-primary-500 hx:dark:bg-primary-400/10 hx:dark:text-primary-600 hx:contrast-more:dark:border-primary-500
|
||||
{{- else }}
|
||||
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50
|
||||
{{- end -}}"
|
||||
href="{{ .link }}"
|
||||
{{ if $external }}target="_blank" rel="noreferrer"{{ end }}
|
||||
>
|
||||
<span class="hx:min-w-0 [word-break:break-word]">{{- .title -}}</span>
|
||||
</a>
|
||||
{{- if $hasChildren }}
|
||||
<button type="button" class="hextra-sidebar-collapsible-button hx:absolute hx:top-1/2 hx:-translate-y-1/2 hx:ltr:right-2 hx:rtl:left-2 hx:shrink-0 hx:cursor-pointer hx:p-0 hx:text-gray-500 hx:dark:text-neutral-400 hx:group-hover:text-gray-900 hx:dark:group-hover:text-gray-50 hx:group-data-[active=true]:text-primary-800 hx:group-data-[active=true]:dark:text-primary-600 hx:hextra-focus-visible-inset" aria-label="{{ (T "toggleSection") | default "Toggle section" }}" aria-expanded="{{ if $open }}true{{ else }}false{{ end }}">
|
||||
{{- template "sidebar-collapsible-button" -}}
|
||||
</button>
|
||||
{{- end }}
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
{{- define "sidebar-collapsible-button" -}}
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" class="hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" class="hx:origin-center hx:transition-transform hx:rtl:-rotate-180"></path></svg>
|
||||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true" focusable="false" class="hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" class="hx:origin-center hx:transition-transform hx:rtl:-rotate-180"></path></svg>
|
||||
{{- end -}}
|
||||
|
||||
Reference in New Issue
Block a user