Skip to content

Commit

Permalink
Refactor single page template
Browse files Browse the repository at this point in the history
  • Loading branch information
markdumay committed Feb 8, 2024
1 parent 5dcb44b commit 00e1695
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
42 changes: 6 additions & 36 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<div class="d-{{ $breakpoint.current }}-none pb-5">{{ partial "assets/toc-dropdown.html" (dict "page" .) }}</div>
{{- 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 -}}
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvass-sidebar" aria-inledby="offcanvas-label">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvas-label">{{ strings.FirstUpper $.Section }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="{{ T "close" }}"></button>
</div>
<div class="offcanvas-body">
{{ . | safeHTML }}
</div>
</div>
{{ end }}

{{ $sidebar | safeHTML }}

<div class="container-xxl flex-fill p-4 px-xxl-0">
{{ if $hasSidebar -}}
{{ if $sidebar -}}
<div class="row row-cols-1 row-cols-{{ $breakpoint.current }}-2 row-cols-{{ $breakpoint.next }}-3">
<div class="col col-{{ $breakpoint.next }}-2 d-none d-{{ $breakpoint.next }}-block sidebar-overflow sticky-top pt-5">
{{ $sidebar | safeHTML }}
</div>
<div class="col-12 col-{{ $breakpoint.current }}-9 col-{{ $breakpoint.next }}-8 mb-5 p-4">
{{ partial "partials/single-main.html" . }}
{{ .Render "single/main" }}
</div>
<div class="col col-{{ $breakpoint.current }}-3 col-{{ $breakpoint.next }}-2 d-none d-{{ $breakpoint.current }}-block pt-5">
{{ $toc | safeHTML }}
Expand All @@ -51,7 +21,7 @@ <h5 class="offcanvas-title" id="offcanvas-label">{{ strings.FirstUpper $.Section
{{ else }}
<div class="row row-cols-1 row-cols-{{ $breakpoint.current }}-2">
<div class="col col-{{ $breakpoint.prev }}-12 col-{{ $breakpoint.current }}-9">
{{ partial "partials/single-main.html" . }}
{{ .Render "single/main" }}
</div>
<div class="col col-{{ $breakpoint.current }}-3 d-none d-{{ $breakpoint.current }}-block">
{{ $toc | safeHTML }}
Expand Down
11 changes: 11 additions & 0 deletions layouts/_default/single/main.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<div class="d-{{ $breakpoint.current }}-none pb-5">{{ partial "assets/toc-dropdown.html" (dict "page" .) }}</div>
{{- end -}}
{{ .Render "single/body" }}

{{ .Render "single/footer" }}
19 changes: 19 additions & 0 deletions layouts/_default/single/sidebar.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvass-sidebar" aria-inledby="offcanvas-label">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvas-label">{{ strings.FirstUpper $.Section }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="{{ T "close" }}"></button>
</div>
<div class="offcanvas-body">
{{ $sidebar | safeHTML }}
</div>
</div>
{{ else if .Site.Params.navigation.sidebar }}
&nbsp;
{{ end }}

0 comments on commit 00e1695

Please sign in to comment.