diff --git a/layouts/partials/sidebar/render-tree-branch-without-leaf.html b/layouts/partials/sidebar/render-tree-branch-without-leaf.html
new file mode 100644
index 0000000..b3e316a
--- /dev/null
+++ b/layouts/partials/sidebar/render-tree-branch-without-leaf.html
@@ -0,0 +1,15 @@
+{{- $entry := . -}}
+
+
+
+ {{- range $entry }}
+ {{- $shouldOpen := .open | default false }}
+ -
+ {{- template "sidebar-item-link" (dict "context" . "active" false "title" .title "link" .link) -}}
+ {{- if .section -}}
+ {{- partial "sidebar/render-tree-branch-without-leaf" .section -}}
+ {{- end -}}
+
+ {{- end -}}
+
+
diff --git a/layouts/partials/sidebar/render-tree.html b/layouts/partials/sidebar/render-tree.html
index ac4c075..a4d5f5f 100644
--- a/layouts/partials/sidebar/render-tree.html
+++ b/layouts/partials/sidebar/render-tree.html
@@ -3,11 +3,16 @@
{{- $pageLink := .page.RelPermalink -}}
{{- range .tree -}}
{{- $active := eq $pageLink .link -}}
- {{- $shouldOpen := or (.open) (hasPrefix $pageLink .link) $active | default true }}
+ {{- $containsPage := hasPrefix $pageLink .link -}}
+ {{- $shouldOpen := or (.open) $containsPage $active | default false }}
{{- template "sidebar-item-link" (dict "context" . "active" $active "title" .title "link" .link) -}}
{{- if .section -}}
- {{- partial "sidebar/render-tree-branch" (dict "context" $context "entry" .section "page" $page) -}}
+ {{- if not $containsPage -}}
+ {{- partialCached "sidebar/render-tree-branch-without-leaf" .section .section -}}
+ {{- else -}}
+ {{- partial "sidebar/render-tree-branch" (dict "context" $context "entry" .section "page" $page) -}}
+ {{- end -}}
{{- end -}}
{{ end }}