Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Flexible featured image name #2799

Merged
merged 6 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/wowchemy/layouts/partials/jsonld/article.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<!--unformattedContent-->
{{- $page := .page }}
{{ $summary := .summary }}
{{/* Search for an image "*featured*" in post folder */}}
{{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }}
{{ $filename := $page.Params.image.filename }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ if eq $featured_image nil }}
{{/* First search in post folder */}}
{{ $featured_image = ($page.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $featured_image nil}} {{ $featured_image = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{end}}

{{/* Get schema type. */}}
{{ $schema := "Article" }}
Expand Down Expand Up @@ -45,3 +55,4 @@
"description": {{$summary}}
}
</script>
<!--unformattedContent-->
13 changes: 12 additions & 1 deletion modules/wowchemy/layouts/partials/jsonld/event.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<!--unformattedContent-->
{{ $page := .page }}
{{ $summary := .summary }}
{{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Search for an image "*featured*" in post folder */}}
{{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := .Params.image.filename }}
{{ if eq $featured_image nil }}
{{/* First search in post folder */}}
{{ $featured_image = (.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $featured_image nil}} {{ $featured_image = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{end}}
{{ $author := partial "functions/get_author_name" $page }}

<script type="application/ld+json">
Expand Down Expand Up @@ -45,3 +55,4 @@
"description": {{$summary}}
}
</script>
<!--unformattedContent-->
12 changes: 12 additions & 0 deletions modules/wowchemy/layouts/partials/page_header.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<!--unformattedContent-->
{{ $page := . }}
{{/* Search for an image "*featured*" in post folder */}}
{{ $featured := (.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := .Params.image.filename }}
{{ if eq $featured nil }}
{{/* First search in post folder */}}
{{ $featured = (.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $featured nil}} {{ $featured = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{end}}

{{ $anchor := $page.Params.image.focal_point | default "Smart" }}

{{/* Set default titles for node pages */}}
Expand Down Expand Up @@ -97,3 +108,4 @@ <h1>{{ $title }}</h1>
{{end}}
</div>
{{end}}
<!--unformattedContent-->
11 changes: 11 additions & 0 deletions modules/wowchemy/layouts/partials/site_head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ $scr := .Scratch }}
<!--unformattedContent-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down Expand Up @@ -247,7 +248,16 @@

{{/* Get page image for sharing. */}}
{{ $sharing_image := resources.GetMatch (path.Join "media" "sharing.*") }}
{{/* Search for an image "*featured*" in post folder */}}
{{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := .Params.image.filename }}
{{ if eq $featured_image nil }}
{{/* First search in post folder */}}
{{ $featured_image = (.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $featured_image nil}} {{ $featured_image = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{end}}
{{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }}
{{ $has_logo := fileExists "assets/media/logo.png" | or (fileExists "assets/media/logo.svg") }}
{{ $og_image := "" }}
Expand Down Expand Up @@ -318,3 +328,4 @@
{{ end }}
{{ partial "functions/get_hook" (dict "hook" "head-end" "context" .) }}
</head>
<!--unformattedContent-->
23 changes: 16 additions & 7 deletions modules/wowchemy/layouts/partials/views/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,25 @@
{{ partial "page_metadata" (dict "page" $item "is_list" 1) }}
{{ end }}

{{/* Search for an image "*featured*" in post folder */}}
{{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := $item.Params.image.filename }}
{{ if eq $resource nil }}
{{/* First search in post folder */}}
{{ $resource = ($item.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $resource nil}} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{ end }}
{{ $anchor := $item.Params.image.focal_point | default "Smart" }}
{{ with $resource }}
{{ $image := .Fill (printf "808x455 webp %s" $anchor) }}
<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>
<div class="img-hover-zoom">
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
class="article-banner" alt="{{ $item.Title }}" loading="lazy">
</div>
</a>
{{ $image := .Fill (printf "808x455 webp %s" $anchor) }}
<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>
<div class="img-hover-zoom">
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
class="article-banner" alt="{{ $item.Title }}" loading="lazy">
</div>
</a>
{{end}}

<div class="section-subheading article-title mb-1 mt-3">
Expand Down
21 changes: 16 additions & 5 deletions modules/wowchemy/layouts/partials/views/compact.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!--unformattedContent-->
{{ $item := .item }}

{{/* Dynamic view adjusts to content type. */}}
Expand Down Expand Up @@ -74,13 +75,23 @@

</div>
<div class="ml-3">
{{/* Search for an image "*featured*" in post folder */}}
{{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := $item.Params.image.filename }}
{{ if eq $resource nil }}
{{/* First search in post folder */}}
{{ $resource = ($item.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $resource nil}} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{ end }}
{{ with $resource }}
{{ $image := .Resize "150x webp" }}
<a href="{{$link}}" {{ $target | safeHTMLAttr }}>
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
</a>
{{ $image := .Resize "150x webp" }}
<a href="{{$link}}" {{ $target | safeHTMLAttr }}>
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
</a>
{{end}}
</div>
</div>
<!--unformattedContent-->
9 changes: 9 additions & 0 deletions modules/wowchemy/layouts/partials/views/masonry.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
{{ $summary = $item.Summary }}
{{ end }}

{{/* Search for an image "*featured*" in post folder */}}
{{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := $item.Params.image.filename }}
{{ if eq $resource nil }}
{{/* First search in post folder */}}
{{ $resource = ($item.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $resource nil}} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{ end }}

<div class="card">
{{ with $resource }}
Expand Down
20 changes: 15 additions & 5 deletions modules/wowchemy/layouts/partials/views/showcase.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@

</div>
<div class="col-12 col-md-6 order-first {{$order}}">
{{/* Search for an image "*featured*" in post folder */}}
{{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $filename := $item.Params.image.filename }}
{{ if eq $resource nil }}
{{/* First search in post folder */}}
{{ $resource = ($item.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in media/ folder */}}
{{ if eq $resource nil}} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{ end }}

{{ with $resource }}
{{ $image := .Resize "540x webp" }}
{{if $do_link}}<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{end}}
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
{{if $do_link}}</a>{{end}}
{{ $image := .Resize "540x webp" }}
{{if $do_link}}<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{end}}
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
{{if $do_link}}</a>{{end}}
{{end}}
</div>
</div>
Expand Down