From 00e169512c557fec352ef2b81170d8d79eed2e61 Mon Sep 17 00:00:00 2001 From: Mark Dumay Date: Thu, 8 Feb 2024 05:16:04 +0100 Subject: [PATCH] Refactor single page template --- layouts/_default/single.html | 42 ++++------------------------ layouts/_default/single/main.html | 11 ++++++++ layouts/_default/single/sidebar.html | 19 +++++++++++++ 3 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 layouts/_default/single/main.html create mode 100644 layouts/_default/single/sidebar.html diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 7051484e..783a1030 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,48 +1,18 @@ -{{- define "partials/single-main.html" -}} - {{- $breakpoint := $.Scratch.Get "breakpoint" -}} - {{ if .Site.Params.navigation.breadcrumb }}{{ partial "assets/breadcrumb.html" (dict "page" .) }}{{ end -}} - - {{ .Render "single/header" }} - - {{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}} -
{{ partial "assets/toc-dropdown.html" (dict "page" .) }}
- {{- end -}} - {{ .Render "single/body" }} - - {{ .Render "single/footer" }} -{{ end -}} - {{ define "main" -}} - {{- $menu := .Scratch.Get "sidebar" -}} - {{- $version := .Scratch.Get "version" -}} {{- $breakpoint := $.Scratch.Get "breakpoint" -}} - - {{ $sidebar := "" }} - {{- $hasSidebar := .Site.Params.navigation.sidebar | default true -}} - {{ if and $menu $hasSidebar }}{{ $sidebar = partial "assets/sidebar.html" (dict "page" . "menu" $menu "version" $version) }}{{ end }} - + {{ $sidebar := .Render "single/sidebar" }} {{ $toc := .Render "single/panel-toc" }} - {{ with $sidebar -}} -
-
-
{{ strings.FirstUpper $.Section }}
- -
-
- {{ . | safeHTML }} -
-
- {{ end }} - + {{ $sidebar | safeHTML }} +
- {{ if $hasSidebar -}} + {{ if $sidebar -}}
- {{ partial "partials/single-main.html" . }} + {{ .Render "single/main" }}
{{ $toc | safeHTML }} @@ -51,7 +21,7 @@
{{ strings.FirstUpper $.Section {{ else }}
- {{ partial "partials/single-main.html" . }} + {{ .Render "single/main" }}
{{ $toc | safeHTML }} diff --git a/layouts/_default/single/main.html b/layouts/_default/single/main.html new file mode 100644 index 00000000..a8448b53 --- /dev/null +++ b/layouts/_default/single/main.html @@ -0,0 +1,11 @@ +{{- $breakpoint := $.Scratch.Get "breakpoint" -}} +{{ if .Site.Params.navigation.breadcrumb }}{{ partial "assets/breadcrumb.html" (dict "page" .) }}{{ end -}} + +{{ .Render "single/header" }} + +{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}} +
{{ partial "assets/toc-dropdown.html" (dict "page" .) }}
+{{- end -}} +{{ .Render "single/body" }} + +{{ .Render "single/footer" }} diff --git a/layouts/_default/single/sidebar.html b/layouts/_default/single/sidebar.html new file mode 100644 index 00000000..d20b7299 --- /dev/null +++ b/layouts/_default/single/sidebar.html @@ -0,0 +1,19 @@ +{{- $menu := .Scratch.Get "sidebar" -}} +{{- $version := .Scratch.Get "version" -}} +{{ $sidebar := "" }} +{{- $hasSidebar := .Site.Params.navigation.sidebar | default true -}} +{{ if and $menu $hasSidebar }}{{ $sidebar = partial "assets/sidebar.html" (dict "page" . "menu" $menu "version" $version) }}{{ end }} + +{{ if $sidebar -}} +
+
+
{{ strings.FirstUpper $.Section }}
+ +
+
+ {{ $sidebar | safeHTML }} +
+
+{{ else if .Site.Params.navigation.sidebar }} +   +{{ end }}