Skip to content

Commit

Permalink
Merge pull request #570 from gethinode/develop
Browse files Browse the repository at this point in the history
Support content view templates for single pages
  • Loading branch information
markdumay committed Oct 18, 2023
2 parents 2ca2009 + 02ca727 commit b9699ab
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 141 deletions.
173 changes: 32 additions & 141 deletions layouts/_default/single.html
@@ -1,118 +1,15 @@
{{- define "partials/header.html" -}}
{{ if site.Params.navigation.breadcrumb }}{{ partial "assets/breadcrumb.html" . }}{{ end -}}
{{ if in (slice "docs" "minimal") .Layout }}
{{ with .Title }}<p class="display-4 mt-5">{{ . }}</p>{{ end }}
{{ partial "assets/sharing.html" . }}
<p class="lead mb-5">{{ .Description }}</p>
{{ else }}
{{ $lastmodstr := (partial "utilities/date.html" (dict "date" .Lastmod "format" "long")) -}}
{{ $datestr := (partial "utilities/date.html" (dict "date" .Date "format" "long")) -}}
{{ with .Title }}<p class="display-4 mt-5">{{ . }}</p>{{ end }}
<small class="text-body-secondary text-uppercase">
{{ $datestr | i18n "postedOnDate" -}}
{{ if ne $datestr $lastmodstr -}}&nbsp;({{ $lastmodstr | i18n "lastModified" }}){{ end }} &bull;
{{ .ReadingTime | lang.FormatNumber 0 }}&nbsp;{{ i18n "minutesShort" }} {{ i18n "read" }} &bull;
{{ .WordCount | lang.FormatNumber 0 }}&nbsp;{{ i18n "words" }}
</small>
{{- define "partials/single-main.html" -}}
{{ if .Site.Params.navigation.breadcrumb }}{{ partial "assets/breadcrumb.html" . }}{{ end -}}

{{- if gt (len (.GetTerms "tags")) 0 -}}
<div class="mt-3">
<div class="d-none-dark">
<div class="hstack gap-1">
{{ range (.GetTerms "tags") -}}
{{- $url := (path.Join .Page.RelPermalink) | relLangURL -}}
{{ partial "assets/button.html" (dict "href" $url "title" .LinkTitle "color" "light" "size" "sm") }}
{{ end -}}
</div>
</div>

<div class="d-none-light">
<div class="hstack gap-1">
{{ range (.GetTerms "tags") -}}
{{- $url := (path.Join .Page.RelPermalink) | relLangURL -}}
{{ partial "assets/button.html" (dict "href" $url "title" .LinkTitle "color" "primary" "size" "sm" "outline" "true") }}
{{ end -}}
</div>
</div>
</div>
{{- end -}}
{{ partial "assets/sharing.html" . }}
<p class="lead mb-5 mt-3">{{ .Description }}</p>
{{ end }}
{{ end -}}
{{ .Render "single/header" }}

{{ define "partials/body.html" -}}
{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}}
<div class="d-md-none pb-5">{{ partial "assets/toc-dropdown.html" . }}</div>
{{- end -}}

{{ if not (in (slice "docs" "minimal") .Layout) }}
{{- $thumbnail := "" -}}
{{- $credits := "" -}}

{{- if reflect.IsMap .Params.Thumbnail -}}
{{- $thumbnail = .Params.Thumbnail.url -}}
{{- $author := "" -}}
{{- if and .Params.Thumbnail.authorURL "text" .Params.Thumbnail.author }}
{{- $author = partial "utilities/link" (dict "destination" .Params.Thumbnail.authorURL "text" .Params.Thumbnail.author) -}}
{{- else if .Params.Thumbnail.author }}
{{- $author = .Params.Thumbnail.author -}}
{{- end -}}

{{- $origin := "" -}}
{{- if and .Params.Thumbnail.originURL "text" .Params.Thumbnail.origin }}
{{- $origin = partial "utilities/link" (dict "destination" .Params.Thumbnail.originURL "text" .Params.Thumbnail.origin) -}}
{{- else if .Params.Thumbnail.origin }}
{{- $origin = .Params.Thumbnail.origin -}}
{{- end }}

{{- if and $author $origin }}
{{ $credits = printf (T "photoFull") $author $origin }}
{{ else if $author }}
{{ $credits = T "photoShort" $author }}
{{ end }}
{{ else }}
{{- $thumbnail = .Params.Thumbnail -}}
{{ if or .Params.photoCredits .Params.photoSource }}
{{ warnf "DEPRECATED: frontmatter variables `photoCredits` and `photoSource` have been deprecated in release v0.18: %s" .RelPermalink }}
{{ end }}
{{- if and .Params.photoCredits .Params.PhotoSource }}{{ $credits = printf (T "photoFull") .Params.photoCredits .Params.PhotoSource }}{{ end -}}
{{- end -}}

{{ if $thumbnail -}}
{{- partial "assets/image.html" (dict "url" $thumbnail "ratio" "21x9" "outerClass" "img-wrap" "innerClass" "rounded" "title" .Params.title "caption" $credits) -}}
{{ end -}}
{{ end }}

{{ .Render "single/body" }}
{{ partial "utilities/ProcessContent" (dict "page" .Page "raw" .RawContent) }}
{{ end -}}

{{ define "partials/footer.html" -}}
{{ if eq .Layout "docs" }}
<div class="mt-5 small">
{{ partial "utilities/git.html" . }}
</div>
{{ else if ne .Layout "minimal" }}
<div class="row row-cols-2 mt-5 mb-3">
<div class="col">
{{ with .NextInSection -}}
{{ $next := . -}}
{{ with .OutputFormats.Get "html" -}}
<a class="next" href="{{ $next.RelPermalink }}">
{{- partial "assets/icon.html" (dict "icon" "fas arrow-left") }}&nbsp;{{ $next.LinkTitle }}</a>
{{- end -}}
{{ end -}}
</div>
<div class="col text-end">
{{ with .PrevInSection -}}
{{ $prev := . -}}
{{ with .OutputFormats.Get "html" -}}
<a class="previous" href="{{ $prev.RelPermalink }}">{{ $prev.LinkTitle }}&nbsp;{{- partial "assets/icon.html" (dict "icon" "fas arrow-right") }}</a>
{{- end -}}
{{ end -}}
</div>
</div>
{{ end }}
{{ .Render "single/footer" }}
{{- if and .Site.Params.comments.enabled .Params.showComments | default true -}}
<hr>
{{ partial "assets/comments.html" . }}
Expand All @@ -127,65 +24,59 @@

{{- $menu := .Scratch.Get "sidebar" -}}
{{- $version := .Scratch.Get "version" -}}
{{- $sidebar := .Site.Params.navigation.sidebar | default true -}}
{{ if and $menu $sidebar -}}

{{ $sidebar := "" }}
{{- $hasSidebar := .Site.Params.navigation.sidebar | default true -}}
{{ if and $menu $hasSidebar }}{{ $sidebar = partial "assets/sidebar.html" (dict "page" . "menu" $menu "version" $version) }}{{ end }}

{{ $toc := "" }}
{{- $hasTOC := and .Site.Params.navigation.toc .Params.includeToc | default true -}}
{{ if $hasTOC }}{{ $toc = partial "assets/toc.html" (dict "page" . "download" $download) }}{{ end -}}

{{ 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>
<h5 class="offcanvas-title" id="offcanvas-label">{{ strings.FirstUpper $.Section }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
{{ partial "assets/sidebar" (dict "page" . "menu" $menu "version" $version) }}
{{ . | safeHTML }}
</div>
</div>

<div class="container-xxl p-4 px-xxl-0">
{{ end }}

<div class="container-xxl p-4 px-xxl-0">
{{ if and $menu $hasSidebar -}}
<div class="row row-cols-md-2 row-cols-lg-3">
<div class="col col-md-3 col-lg-2 d-none pt-5 d-md-block sidebar-overflow sticky-top">
{{ partial "assets/sidebar" (dict "page" . "menu" $menu "version" $version) }}
{{ $sidebar | safeHTML }}
</div>
<div class="col col-md-9 col-lg-8 mb-5 p-4">
{{ partial "partials/header.html" . }}
{{ partial "partials/body.html" . }}
{{ partial "partials/footer.html" . }}
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-lg-2 d-none d-lg-block pt-5">
{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}}
{{ partial "assets/toc.html" (dict "page" . "download" $download) -}}
{{ end -}}
{{ $toc | safeHTML }}
</div>
</div>
</div>
{{ else if $sidebar }}
<div class="container-xxl px-4 px-xxl-0">
{{ else if $hasSidebar }}
<div class="row row-cols-1 row-cols-sm-3">
<div class="col col-md-2 d-none d-md-block"></div>
<div class="col col-sm-12 col-md-8">
{{ partial "partials/header.html" . }}
{{ partial "partials/body.html" . }}
{{ partial "partials/footer.html" . }}
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-md-2 d-none d-md-block">
{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}}
{{ partial "assets/toc.html" (dict "page" . "download" $download) -}}
{{ end -}}
{{ $toc | safeHTML }}
</div>
</div>
</div>
{{ else }}
<div class="container-xxl px-4 px-xxl-0">
{{ else }}
<div class="row row-cols-1 row-cols-sm-2">
<div class="col col-sm-12 col-md-9">
{{ partial "partials/header.html" . }}
{{ partial "partials/body.html" . }}
{{ partial "partials/footer.html" . }}
{{ partial "partials/single-main.html" . }}
</div>
<div class="col col-md-3 d-none d-md-block">
{{- if and .Site.Params.navigation.toc .Params.includeToc | default true -}}
{{ partial "assets/toc.html" (dict "page" . "download" $download) -}}
{{ end -}}
{{ $toc | safeHTML }}
</div>
</div>
</div>
{{ end -}}
{{ end -}}
</div>
{{ end -}}
1 change: 1 addition & 0 deletions layouts/_default/single/body.html
@@ -0,0 +1 @@
{{- partial "single/thumbnail.html" . -}}
20 changes: 20 additions & 0 deletions layouts/_default/single/footer.html
@@ -0,0 +1,20 @@
<div class="row row-cols-2 mt-5 mb-3">
<div class="col">
{{ with .NextInSection -}}
{{ if .OutputFormats.Get "html" -}}
<a class="next" href="{{ .RelPermalink }}">
{{- partial "assets/icon.html" (dict "icon" "fas arrow-left" "spacing" false) }}&nbsp;{{ .LinkTitle }}
</a>
{{- end -}}
{{ end -}}
</div>
<div class="col text-end">
{{ with .PrevInSection -}}
{{ if .OutputFormats.Get "html" -}}
<a class="previous" href="{{ .RelPermalink }}">
{{ .LinkTitle }}&nbsp;{{- partial "assets/icon.html" (dict "icon" "fas arrow-right" "spacing" false) }}
</a>
{{- end -}}
{{ end -}}
</div>
</div>
33 changes: 33 additions & 0 deletions layouts/_default/single/header.html
@@ -0,0 +1,33 @@
{{ $lastmodstr := (partial "utilities/date.html" (dict "date" .Lastmod "format" "long")) -}}
{{ $datestr := (partial "utilities/date.html" (dict "date" .Date "format" "long")) -}}
{{ with .Title }}<p class="display-4 mt-5">{{ . }}</p>{{ end }}
<small class="text-body-secondary text-uppercase">
{{ $datestr | i18n "postedOnDate" -}}
{{ if ne $datestr $lastmodstr -}}&nbsp;({{ $lastmodstr | i18n "lastModified" }}){{ end }} &bull;
{{ .ReadingTime | lang.FormatNumber 0 }}&nbsp;{{ i18n "minutesShort" }} {{ i18n "read" }} &bull;
{{ .WordCount | lang.FormatNumber 0 }}&nbsp;{{ i18n "words" }}
</small>

{{- if gt (len (.GetTerms "tags")) 0 -}}
<div class="mt-3">
<div class="d-none-dark">
<div class="hstack gap-1">
{{ range (.GetTerms "tags") -}}
{{- $url := (path.Join .Page.RelPermalink) | relLangURL -}}
{{ partial "assets/button.html" (dict "href" $url "title" .LinkTitle "color" "light" "size" "sm") }}
{{ end -}}
</div>
</div>

<div class="d-none-light">
<div class="hstack gap-1">
{{ range (.GetTerms "tags") -}}
{{- $url := (path.Join .Page.RelPermalink) | relLangURL -}}
{{ partial "assets/button.html" (dict "href" $url "title" .LinkTitle "color" "primary" "size" "sm" "outline" "true") }}
{{ end -}}
</div>
</div>
</div>
{{- end -}}
{{ partial "assets/sharing.html" . }}
<p class="lead mb-5 mt-3">{{ .Description }}</p>
1 change: 1 addition & 0 deletions layouts/docs/single/body.html
@@ -0,0 +1 @@
{{/* Intentionally left blank to suppress thumbnail */}}
3 changes: 3 additions & 0 deletions layouts/docs/single/footer.html
@@ -0,0 +1,3 @@
<div class="mt-5 small">
{{ partial "utilities/git.html" . }}
</div>
3 changes: 3 additions & 0 deletions layouts/docs/single/header.html
@@ -0,0 +1,3 @@
{{ with .Title }}<p class="display-4 mt-5">{{ . }}</p>{{ end }}
{{ partial "assets/sharing.html" . }}
<p class="lead mb-5">{{ .Description }}</p>
1 change: 1 addition & 0 deletions layouts/minimal/single/body.html
@@ -0,0 +1 @@
{{/* Intentionally left blank to suppress thumbnail */}}
1 change: 1 addition & 0 deletions layouts/minimal/single/footer.html
@@ -0,0 +1 @@
{{/* Intentionally left blank to suppress page navigation */}}
3 changes: 3 additions & 0 deletions layouts/minimal/single/header.html
@@ -0,0 +1,3 @@
{{ with .Title }}<p class="display-4 mt-5">{{ . }}</p>{{ end }}
{{ partial "assets/sharing.html" . }}
<p class="lead mb-5">{{ .Description }}</p>
35 changes: 35 additions & 0 deletions layouts/partials/single/thumbnail.html
@@ -0,0 +1,35 @@
{{- $thumbnail := "" -}}
{{- $credits := "" -}}

{{- if reflect.IsMap .Params.Thumbnail -}}
{{- $thumbnail = .Params.Thumbnail.url -}}
{{- $author := "" -}}
{{- if and .Params.Thumbnail.authorURL "text" .Params.Thumbnail.author }}
{{- $author = partial "utilities/link" (dict "destination" .Params.Thumbnail.authorURL "text" .Params.Thumbnail.author) -}}
{{- else if .Params.Thumbnail.author }}
{{- $author = .Params.Thumbnail.author -}}
{{- end -}}

{{- $origin := "" -}}
{{- if and .Params.Thumbnail.originURL "text" .Params.Thumbnail.origin }}
{{- $origin = partial "utilities/link" (dict "destination" .Params.Thumbnail.originURL "text" .Params.Thumbnail.origin) -}}
{{- else if .Params.Thumbnail.origin }}
{{- $origin = .Params.Thumbnail.origin -}}
{{- end }}

{{- if and $author $origin }}
{{ $credits = printf (T "photoFull") $author $origin }}
{{ else if $author }}
{{ $credits = T "photoShort" $author }}
{{ end }}
{{ else }}
{{- $thumbnail = .Params.Thumbnail -}}
{{ if or .Params.photoCredits .Params.photoSource }}
{{ warnf "DEPRECATED: frontmatter variables `photoCredits` and `photoSource` have been deprecated in release v0.18: %s" .RelPermalink }}
{{ end }}
{{- if and .Params.photoCredits .Params.PhotoSource }}{{ $credits = printf (T "photoFull") .Params.photoCredits .Params.PhotoSource }}{{ end -}}
{{- end -}}

{{ if $thumbnail -}}
{{- partial "assets/image.html" (dict "url" $thumbnail "ratio" "21x9" "outerClass" "img-wrap" "innerClass" "rounded" "title" .Params.title "caption" $credits) -}}
{{ end -}}

0 comments on commit b9699ab

Please sign in to comment.