resize card images on the fly; optionally link to image reference page
This commit is contained in:
parent
e3e6b739df
commit
f3d9139033
2 changed files with 124 additions and 92 deletions
|
@ -1,18 +1,29 @@
|
|||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<a href="{{ .Permalink }}" class="index-anchor text-decoration-none">
|
||||
{{ if .Params.img }}
|
||||
<img width="100%"
|
||||
src="{{ .Site.BaseURL }}img/{{ .Params.img }}" alt="{{ .Title }}">
|
||||
{{ else if .Params.teaser }}
|
||||
<div class="card-header">
|
||||
<p class="card-text">{{ .Params.teaser }}</p>
|
||||
</div>
|
||||
{{ else if .Site.Params.defaultImage }}
|
||||
<img width="100%"
|
||||
src="{{ .Site.BaseURL }}img/{{ .Site.Params.defaultImage }}"
|
||||
alt="{{ .Site.Title }}">
|
||||
{{ end }}
|
||||
{{- $img := .Params.img -}}
|
||||
{{- $refImg := "" -}}
|
||||
{{- if .Params.imgRef -}}
|
||||
{{- range where .Site.RegularPages "Params.pageid" "eq" .Params.imgRef -}}
|
||||
{{- $refImg = .Params.img -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if not $img -}}
|
||||
{{- $img = $refImg -}}
|
||||
{{- end -}}
|
||||
{{ if $img -}}
|
||||
{{- $image := (resources.Get (printf "img/%s" $img)).Resize "400x" -}}
|
||||
<img width="100%"
|
||||
src="{{ $image.RelPermalink }}" alt="{{ .Title }}">
|
||||
{{ else if .Params.teaser }}
|
||||
<div class="card-header">
|
||||
<p class="card-text">{{ .Params.teaser }}</p>
|
||||
</div>
|
||||
{{ else if .Site.Params.defaultImage }}
|
||||
<img width="100%"
|
||||
src="{{ .Site.BaseURL }}img/{{ .Site.Params.defaultImage }}"
|
||||
alt="{{ .Site.Title }}">
|
||||
{{ end }}
|
||||
|
||||
<div class="card-body">
|
||||
<span class="card-title h4">{{ .Title | truncate 25 }}</span>
|
||||
|
|
|
@ -1,89 +1,110 @@
|
|||
<div class="col-md-4 mt20">
|
||||
|
||||
{{ if .Params.img -}}
|
||||
<img width="100%" class="mt-3"
|
||||
src="{{ .Site.BaseURL}}img/{{ .Params.img }}" alt="{{ .Params.title }}">
|
||||
{{- else if .Params.teaser -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-body bg-light">
|
||||
<h5 class="card-text">{{ .Params.teaser }}</h5>
|
||||
</div>
|
||||
{{- $refImg := "" -}}
|
||||
{{- $refPage := "" -}}
|
||||
{{- $img := .Params.img -}}
|
||||
{{- if .Params.imgRef -}}
|
||||
{{- range where .Site.RegularPages "Params.pageid" "eq" .Params.imgRef -}}
|
||||
{{- $refImg = .Params.img -}}
|
||||
{{- $refPage = . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if not $img -}}
|
||||
{{- $img = $refImg -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ if $img -}}
|
||||
{{- $image := (resources.Get (printf "img/%s" $img)).Resize "400x" -}}
|
||||
{{- if $refPage -}}
|
||||
<a href="{{ $refPage.Permalink }}"><img
|
||||
width="100%" class="mt-3"
|
||||
src="{{ $image.RelPermalink }}" alt="{{ .Params.title }}"></a>
|
||||
{{- else -}}
|
||||
<img width="100%" class="mt-3"
|
||||
src="{{ $image.RelPermalink }}" alt="{{ .Params.title }}">
|
||||
{{- end -}}
|
||||
{{- else if .Params.teaser -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-body bg-light">
|
||||
<h5 class="card-text">{{ .Params.teaser }}</h5>
|
||||
</div>
|
||||
{{- else if .Site.Params.defaultImage -}}
|
||||
<img width="100%" class="mt-3"
|
||||
src="{{ .Site.BaseURL }}img/{{ .Site.Params.defaultImage }}" alt="dummy">
|
||||
{{- else if .Params.Summary -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-body bg-light">
|
||||
<h5 class="card-text">{{ .Params.Summary }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
{{- else if .Site.Params.defaultImage -}}
|
||||
<img width="100%" class="mt-3"
|
||||
src="{{ .Site.BaseURL }}img/{{ .Site.Params.defaultImage }}"
|
||||
alt="Default Dmage">
|
||||
{{- else if .Params.Summary -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-body bg-light">
|
||||
<h5 class="card-text">{{ .Params.Summary }}</h5>
|
||||
</div>
|
||||
{{- end }}
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{ with .Params.Topics -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h4 class="card-text">{{i18n "topics"}}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ range . -}}
|
||||
{{- $page := $.GetPage (printf "/topics/%s" .) -}}
|
||||
<span class="badge rounded-pill bg-secondary m-1">
|
||||
<a href="{{ $page.Permalink }}">{{ $page.Title }}</a>
|
||||
</span>
|
||||
{{- end }}
|
||||
</div>
|
||||
{{ with .Params.Topics -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h4 class="card-text">{{i18n "topics"}}</h4>
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideParentArticles -}}
|
||||
{{- $related := where .Site.RegularPages "Params.pageid" "in" .Params.parents -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "parent-articles") "id" "parents") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if and (not .Site.Params.hideChildArticles)
|
||||
(ne .Site.Params.showChildArticles "cards") -}}
|
||||
{{- $related := .Site.RegularPages.RelatedTo (keyVals "parents" .Params.pageid) -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "child-articles") "id" "children") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideRelatedArticles -}}
|
||||
{{- $related := .Site.RegularPages.RelatedIndices . "topics" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "related-articles") "id" "related") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideSiblingArticles -}}
|
||||
{{- $related := .Site.RegularPages.RelatedIndices . "parents" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "sibling-articles") "id" "siblings") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideSectionArticles -}}
|
||||
{{- $section := or .Section "posts" -}}
|
||||
{{- $header := or (i18n (printf "articles-in-%s" $section)) (i18n "articles-in-section") -}}
|
||||
{{- $related := first 20 (where .Site.RegularPages "Section" $section) -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" $header "id" "articles-in-section") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideBacklinks -}}
|
||||
{{- $related := .Scratch.Get "backlinks" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "backlinks") "id" "backlinks") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if .Params.showtoc -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h4 class="card-text">{{i18n "toc"}}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ range . -}}
|
||||
{{- $page := $.GetPage (printf "/topics/%s" .) -}}
|
||||
<span class="badge rounded-pill bg-secondary m-1">
|
||||
<a href="{{ $page.Permalink }}">{{ $page.Title }}</a>
|
||||
</span>
|
||||
{{- end }}
|
||||
</div>
|
||||
{{ end -}}
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideParentArticles -}}
|
||||
{{- $related := where .Site.RegularPages "Params.pageid" "in" .Params.parents -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "parent-articles") "id" "parents") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if and (not .Site.Params.hideChildArticles)
|
||||
(ne .Site.Params.showChildArticles "sidebar") -}}
|
||||
{{- $related := .Site.RegularPages.RelatedTo (keyVals "parents" .Params.pageid) -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "child-articles") "id" "children") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideRelatedArticles -}}
|
||||
{{- $related := .Site.RegularPages.RelatedIndices . "topics" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "related-articles") "id" "related") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideSiblingArticles -}}
|
||||
{{- $related := .Site.RegularPages.RelatedIndices . "parents" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "sibling-articles") "id" "siblings") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideSectionArticles -}}
|
||||
{{- $section := or .Section "posts" -}}
|
||||
{{- $header := or (i18n (printf "articles-in-%s" $section)) (i18n "articles-in-section") -}}
|
||||
{{- $related := first 20 (where .Site.RegularPages "Section" $section) -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" $header "id" "articles-in-section") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if not .Site.Params.hideBacklinks -}}
|
||||
{{- $related := .Scratch.Get "backlinks" -}}
|
||||
{{- partial "card-related"
|
||||
(dict "related" $related "header" (i18n "backlinks") "id" "backlinks") -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if .Params.showtoc -}}
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h4 class="card-text">{{i18n "toc"}}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end -}}
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue