diff options
author | Sascha Brendel <mail@lednerb.eu> | 2020-07-27 13:46:23 +0300 |
---|---|---|
committer | Sascha Brendel <mail@lednerb.eu> | 2020-07-27 13:46:23 +0300 |
commit | 6dc4b19464822457ad165c5a2a31982255e97421 (patch) | |
tree | 9a943be7844b60ef001689642f10cacf65b8388b | |
parent | 1d9d1558f227332f570aacb149da4396818aedb0 (diff) |
Refactored partials to work without .Scratch to prevent caching-race-conditions and fix #208
-rw-r--r-- | layouts/_default/list.html | 5 | ||||
-rw-r--r-- | layouts/_default/single.html | 7 | ||||
-rw-r--r-- | layouts/partials/article-wrapper.html | 7 | ||||
-rw-r--r-- | layouts/partials/commento.html | 8 | ||||
-rw-r--r-- | layouts/partials/content-type/article.html | 10 | ||||
-rw-r--r-- | layouts/partials/content-type/audio.html | 18 | ||||
-rw-r--r-- | layouts/partials/content-type/code.html | 10 | ||||
-rw-r--r-- | layouts/partials/content-type/gallery.html | 22 | ||||
-rw-r--r-- | layouts/partials/content-type/link.html | 14 | ||||
-rw-r--r-- | layouts/partials/content-type/page.html | 14 | ||||
-rw-r--r-- | layouts/partials/content-type/picture.html | 10 | ||||
-rw-r--r-- | layouts/partials/content-type/quote.html | 19 | ||||
-rwxr-xr-x | layouts/partials/content-type/video.html | 52 | ||||
-rw-r--r-- | layouts/partials/default-content.html | 63 |
14 files changed, 132 insertions, 127 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 2094da1..d909ce1 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,12 +1,11 @@ {{ define "main" }} {{ $paginator := .Paginate (where .Data.Pages "Type" "ne" "page") (index .Site.Params "paginate" | default 7) }} {{ range where .Paginator.Pages "Type" "ne" "page" }} - {{ .Scratch.Set "singlePage" false }} <!-- RESET singlePage variable --> <div class="article-wrapper u-cf"> {{ if or (fileExists (print "layouts/partials/content-type/" .Type ".html") ) (fileExists (print "themes/bilberry-hugo-theme/layouts/partials/content-type/" .Type ".html")) }} - {{ partial (print "content-type/" .Type ".html") . }} + {{ partial (print "content-type/" .Type ".html") (dict "ctx" . "template_type" "multiple") }} {{ else }} - {{ partial "content-type/article.html" . }} + {{ partial "content-type/article.html" (dict "ctx" . "template_type" "multiple") }} {{ end }} </div> {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 39fa7d1..dd301be 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,10 +1,9 @@ {{ define "main" }} - {{ .Scratch.Set "singlePage" true }} <!-- SET singlePage variable --> <div class="article-wrapper u-cf single"> {{ if or (fileExists (print "layouts/partials/content-type/" .Type ".html") ) (fileExists (print "themes/bilberry-hugo-theme/layouts/partials/content-type/" .Type ".html")) }} - {{ partial (print "content-type/" .Type ".html") . }} + {{ partial (print "content-type/" .Type ".html") (dict "ctx" . "template_type" "single") }} {{ else }} - {{ partial "content-type/article.html" . }} + {{ partial "content-type/article.html" (dict "ctx" . "template_type" "single") }} {{ end }} </div> @@ -14,6 +13,4 @@ {{ partial "commento.html" . }} </div> {{ end }} - - {{ .Scratch.Set "singlePage" false }} <!-- RESET singlePage variable --> {{ end }} diff --git a/layouts/partials/article-wrapper.html b/layouts/partials/article-wrapper.html index 4a97054..08d0710 100644 --- a/layouts/partials/article-wrapper.html +++ b/layouts/partials/article-wrapper.html @@ -1,10 +1,9 @@ {{ with . }} - {{ .Scratch.Set "singlePage" false }} <!-- RESET singlePage variable --> <div class="article-wrapper u-cf"> {{ if or (fileExists (print "layouts/partials/content-type/" .Type ".html") ) (fileExists (print "themes/bilberry-hugo-theme/layouts/partials/content-type/" .Type ".html")) }} - {{ partial (print "content-type/" .Type ".html") . }} + {{ partial (print "content-type/" .Type ".html") (dict "ctx" . "template_type" "multiple") }} {{ else }} - {{ partial "content-type/article.html" . }} + {{ partial "content-type/article.html" (dict "ctx" . "template_type" "multiple") }} {{ end }} </div> -{{end}} +{{ end }} diff --git a/layouts/partials/commento.html b/layouts/partials/commento.html index 7ea64be..7271a20 100644 --- a/layouts/partials/commento.html +++ b/layouts/partials/commento.html @@ -1,4 +1,4 @@ -{{if isset .Site.Params "commentojsurl" }} -<script defer src="{{.Site.Params.commentoJsURL}}"></script> -<div id="commento"></div> -{{end}} +{{ if isset .Site.Params "commentojsurl" }} + <script defer src="{{.Site.Params.commentoJsURL}}"></script> + <div id="commento"></div> +{{ end }} diff --git a/layouts/partials/content-type/article.html b/layouts/partials/content-type/article.html index 149a65f..4a390a3 100644 --- a/layouts/partials/content-type/article.html +++ b/layouts/partials/content-type/article.html @@ -1,9 +1,9 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{ or .Params.icon "fa-pencil-alt" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{ or .ctx.Params.icon "fa-pencil-alt" }}"></i> </a> <article class="default article"> - {{ partial "featured-image.html" . }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "featured-image.html" .ctx }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/audio.html b/layouts/partials/content-type/audio.html index 767bd8a..2fb2b64 100644 --- a/layouts/partials/content-type/audio.html +++ b/layouts/partials/content-type/audio.html @@ -1,35 +1,35 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-music" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-music" }}"></i> </a> <article class="audio"> - {{ partial "featured-image.html" . }} + {{ partial "featured-image.html" .ctx }} - {{ with .Params.spotify }} + {{ with .ctx.Params.spotify }} <div class="responsive-audio spotify"> <iframe src="https://open.spotify.com/embed?uri={{ . }}" width="300" height="80" frameborder="0" allowtransparency="true"></iframe> </div> {{ end }} - {{ with .Params.soundcloud }} + {{ with .ctx.Params.soundcloud }} <div class="responsive-audio soundcloud"> <iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url={{ . }}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true"></iframe> </div> {{ end }} - {{ with .Params.tunein }} + {{ with .ctx.Params.tunein }} <div class="responsive-audio tunein"> <iframe src="https://tunein.com/embed/player/{{ . }}/" style="width:100%; height:100px;" scrolling="no" frameborder="no"></iframe> </div> {{ end }} - {{ with .Params.mixcloud }} + {{ with .ctx.Params.mixcloud }} <div class="responsive-audio mixcloud"> <iframe width="100%" height="120" src="https://www.mixcloud.com/widget/iframe/?hide_cover=1&feed=/{{ . }}/" frameborder="0"></iframe> </div> {{ end }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/code.html b/layouts/partials/content-type/code.html index 01395a5..2a69d3e 100644 --- a/layouts/partials/content-type/code.html +++ b/layouts/partials/content-type/code.html @@ -1,9 +1,9 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-code" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-code" }}"></i> </a> <article class="default article"> - {{ partial "featured-image.html" . }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "featured-image.html" .ctx }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/gallery.html b/layouts/partials/content-type/gallery.html index 88d992f..5f01cd2 100644 --- a/layouts/partials/content-type/gallery.html +++ b/layouts/partials/content-type/gallery.html @@ -1,34 +1,34 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{ or .Params.icon "fa-camera" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{ or .ctx.Params.icon "fa-camera" }}"></i> </a> <article class="gallery"> - {{ if and (isset .Params "gallery") (ne .Params.gallery "") }} + {{ if and (isset .ctx.Params "gallery") (ne .ctx.Params.gallery "") }} <div class="flexslider"> <ul class="slides"> - {{ range .Params.gallery }} + {{ range .ctx.Params.gallery }} <li><img src="{{ . | relURL }}" /></li> {{ end }} </ul> </div> - {{ else if ne .Params.imageSlider false }} + {{ else if ne .ctx.Params.imageSlider false }} <div class="flexslider"> <ul class="slides"> - {{ if and (.Site.Params.resizeImages | default true) (.Params.resizeImages | default true) }} - {{ range .Resources.ByType "image" }} + {{ if and (.ctx.Site.Params.resizeImages | default true) (.ctx.Params.resizeImages | default true) }} + {{ range .ctx.Resources.ByType "image" }} <li><img src="{{ (.Fill "700x350 q95").RelPermalink }}" /></li> {{ end }} {{ else }} - {{ range .Resources.ByType "image" }} + {{ range .ctx.Resources.ByType "image" }} <li><img src="{{ .RelPermalink }}" /></li> {{ end }} {{ end }} </ul> </div> {{ else}} - {{ partial "featured-image.html" . }} + {{ partial "featured-image.html" .ctx }} {{ end }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/link.html b/layouts/partials/content-type/link.html index a21068d..532686e 100644 --- a/layouts/partials/content-type/link.html +++ b/layouts/partials/content-type/link.html @@ -1,13 +1,13 @@ -<a class="bubble" href="{{ .Params.link }}" target="_blank"> - <i class="fas fa-fw {{ or .Params.icon "fa-link" }}"></i> +<a class="bubble" href="{{ .ctx.Params.link }}" target="_blank"> + <i class="fas fa-fw {{ or .ctx.Params.icon "fa-link" }}"></i> </a> <article class="link"> - {{ with .Params.featuredImage }} - <img src="{{ . }}" class="featured-image" alt=""> + {{ with .ctx.Params.featuredImage }} + <img src="{{ . }}" class="featured-image" alt=""> {{ end }} - <a href="{{ .Params.link }}" target="_blank"> - <h4>{{ .Title }}</h4> - {{ .Content }} + <a href="{{ .ctx.Params.link }}" target="_blank"> + <h4>{{ .ctx.Title }}</h4> + {{ .ctx.Content }} </a> </article> diff --git a/layouts/partials/content-type/page.html b/layouts/partials/content-type/page.html index 2aa1eb4..f9a36b3 100644 --- a/layouts/partials/content-type/page.html +++ b/layouts/partials/content-type/page.html @@ -1,14 +1,14 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-file" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-file" }}"></i> </a> <article class="default article"> - {{ partial "featured-image.html" . }} - {{ partial "default-content.html" . }} + {{ partial "featured-image.html" .ctx }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} - {{ with .Params.link }} - <script>window.location = {{ . | relURL }}</script> + {{ with .ctx.Params.link }} + <script>window.location = {{ . | relURL }}</script> {{ end }} - {{ partial "article-footer.html" . }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/picture.html b/layouts/partials/content-type/picture.html index df9a4a5..85526ed 100644 --- a/layouts/partials/content-type/picture.html +++ b/layouts/partials/content-type/picture.html @@ -1,9 +1,9 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-camera" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-camera" }}"></i> </a> <article class="picture"> - {{ partial "featured-image.html" . }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "featured-image.html" .ctx }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/content-type/quote.html b/layouts/partials/content-type/quote.html index 32de1e2..caaf15e 100644 --- a/layouts/partials/content-type/quote.html +++ b/layouts/partials/content-type/quote.html @@ -1,14 +1,19 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-quote-right" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-quote-right" }}"></i> </a> <article class="quote"> - {{ with .Params.featuredImage }} - <img src="{{ . }}" class="featured-image" alt=""> + {{ with .ctx.Params.featuredImage }} + <img src="{{ . }}" class="featured-image" alt=""> {{ end }} + <blockquote> - {{ .Content }} - {{ $urlValue := replace .Params.author " " "-" | lower}} - <cite><a href="{{ (print "/author/" $urlValue) | relLangURL }}">{{ .Params.author }}</a></cite> + {{ .ctx.Content }} + {{ $urlValue := replace .ctx.Params.author " " "-" | lower}} + <cite> + <a href="{{ (print "/author/" $urlValue) | relLangURL }}"> + {{ .ctx.Params.author }} + </a> + </cite> </blockquote> </article> diff --git a/layouts/partials/content-type/video.html b/layouts/partials/content-type/video.html index c989bad..36afbcc 100755 --- a/layouts/partials/content-type/video.html +++ b/layouts/partials/content-type/video.html @@ -1,37 +1,37 @@ -<a class="bubble" href="{{ .Permalink }}"> - <i class="fas fa-fw {{or .Params.icon "fa-video" }}"></i> +<a class="bubble" href="{{ .ctx.Permalink }}"> + <i class="fas fa-fw {{or .ctx.Params.icon "fa-video" }}"></i> </a> <article class="video"> - {{ partial "featured-image.html" . }} + {{ partial "featured-image.html" .ctx }} - {{ with .Params.youtube }} - <div class="responsive-video youtube"> - <iframe src="https://www.youtube-nocookie.com/embed/{{ . }}?rel=0" frameborder="0" allowfullscreen></iframe> - </div> + {{ with .ctx.Params.youtube }} + <div class="responsive-video youtube"> + <iframe src="https://www.youtube-nocookie.com/embed/{{ . }}?rel=0" frameborder="0" allowfullscreen></iframe> + </div> {{ end }} - {{ with .Params.vimeo }} - <div class="responsive-video vimeo"> - <iframe src="https://player.vimeo.com/video/{{ . }}" frameborder="0" webkitallowfullscreen mozallowfullscreen - allowfullscreen></iframe> - </div> + + {{ with .ctx.Params.vimeo }} + <div class="responsive-video vimeo"> + <iframe src="https://player.vimeo.com/video/{{ . }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> + </div> {{ end }} - {{ with .Params.prezi }} - <div class="responsive-video prezi"> - <iframe src="https://prezi.com/embed/{{ . }}/" frameborder="0" webkitallowfullscreen mozallowfullscreen - allowfullscreen></iframe> - </div> + + {{ with .ctx.Params.prezi }} + <div class="responsive-video prezi"> + <iframe src="https://prezi.com/embed/{{ . }}/" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> + </div> {{ end }} - {{ if isset .Params "mp4video" }} - <div class="responsive-video local"> - <video width="100%" controls poster="{{ .Params.mp4videoImage }}"> - <source src="{{ .Params.mp4video }}" type="video/mp4"> - Your browser does not support the video tag. - </video> - </div> + {{ if isset .ctx.Params "mp4video" }} + <div class="responsive-video local"> + <video width="100%" controls poster="{{ .ctx.Params.mp4videoImage }}"> + <source src="{{ .ctx.Params.mp4video }}" type="video/mp4"> + Your browser does not support the video tag. + </video> + </div> {{ end }} - {{ partial "default-content.html" . }} - {{ partial "article-footer.html" . }} + {{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }} + {{ partial "article-footer.html" .ctx }} </article> diff --git a/layouts/partials/default-content.html b/layouts/partials/default-content.html index 402fd57..d072433 100644 --- a/layouts/partials/default-content.html +++ b/layouts/partials/default-content.html @@ -1,46 +1,51 @@ <div class="content"> - <h1 class="article-title"><a href="{{ .Permalink }}">{{ .Title }}</a></h1> + <h1 class="article-title"> + <a href="{{ .ctx.Permalink }}"> + {{ .ctx.Title }} + </a> + </h1> + <div class="meta"> - {{ if ( .Params.showDate | default true ) }} - {{ if (.Site.Params.enableMomentJs | default true ) }} - <span class="date moment">{{ .PublishDate.Format "2006-01-02" }}</span> - {{ else }} - <span class="date">{{ .PublishDate.Format (.Site.Params.DateFormat | default "2006-01-02") }}</span> - {{ end }} + {{ if ( .ctx.Params.showDate | default true ) }} + {{ if ( .ctx.Site.Params.enableMomentJs | default true ) }} + <span class="date moment">{{ .ctx.PublishDate.Format "2006-01-02" }}</span> + {{ else }} + <span class="date">{{ .ctx.PublishDate.Format (.ctx.Site.Params.DateFormat | default "2006-01-02") }}</span> + {{ end }} {{ end }} - {{ if (.Site.Params.showReadingTime | default false ) }} - <span class="readingTime">{{ i18n "readingTime" .ReadingTime }}</span> + {{ if ( .ctx.Site.Params.showReadingTime | default false ) }} + <span class="readingTime">{{ i18n "readingTime" .ctx.ReadingTime }}</span> {{ end }} - {{ with .Params.categories }} - <span class="categories"> - {{ range . }} - {{ $urlValue := replace . " " "-" | lower}} - {{ with $.Site.GetPage (printf "/categories/%s" $urlValue) }} - <a href="{{ .Permalink }}">{{ .Title }}</a> + {{ with .ctx.Params.categories }} + <span class="categories"> + {{ range . }} + {{ $urlValue := replace . " " "-" | lower}} + {{ with $.Site.GetPage (printf "/categories/%s" $urlValue) }} + <a href="{{ .Permalink }}">{{ .Title }}</a> + {{ end }} {{ end }} - {{ end }} - </span> + </span> {{ end }} {{ with .Params.author }} - <span class="author"> - {{ $urlValue := replace . " " "-" | lower}} - {{ with $.Site.GetPage (printf "/author/%s" $urlValue ) }} - <a href="{{ .Permalink }}">{{ .Title }}</a> - {{ end }} - </span> + <span class="author"> + {{ $urlValue := replace . " " "-" | lower}} + {{ with $.Site.GetPage (printf "/author/%s" $urlValue ) }} + <a href="{{ .Permalink }}">{{ .Title }}</a> + {{ end }} + </span> {{ end }} </div> - {{ if or (.Scratch.Get "singlePage") (.Params.noSummary) }} - {{ .Content }} + {{ if or (eq .template_type "single") (.ctx.Params.noSummary) }} + {{ .ctx.Content }} {{ else }} - {{ .Summary }} + {{ .ctx.Summary }} - {{ if .Truncated }} - <a href="{{ .Permalink }}" class="more">{{ i18n "continueReading" }}</a> - {{ end }} + {{ if .ctx.Truncated }} + <a href="{{ .ctx.Permalink }}" class="more">{{ i18n "continueReading" }}</a> + {{ end }} {{ end }} </div> |