Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
I found another solution but get error <.Scratch.Set> “can’t evaluate field Scratch in type string”. Where is mistake?
Post card takes post image then use {{ partial “imgoptim.html” . }}
<article class="post-card">
<div class="featured-image">
<a href="{{ .RelPermalink }}" class="card-link" aria-label="{{ .Params.title }}"></a>
{{- with .Params.image -}}
{{ partial "imgoptim.html" . }}
{{- end }}
</div>
<div class="about-post">
<div class="tags">
{{ with .Params.tags }}
{{- range first 1 . -}}
<a class="tag-wrapper" href="/temat/{{ . | urlize}}/">{{ . }}</a>
{{- end -}}
{{ end }}
<div class="break"></div>
{{ with .Params.tags }}
{{- range first 2 (after 1 . ) }}
<a class="tag-wrapper" href="/temat/{{ . | urlize}}/">{{ . }}</a>
{{- end -}}
{{ end }}
</div>
<h2 class="post-card-title"><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
<p class="post-summary">{{ .Summary }}</p>
</div>
</article>
partial “imgoptim.html”
{{/* get file that matches the filename as specified as src="" in shortcode */}}
{{ $src := resources.GetMatch "{{ . }}" }}
{{/* set image sizes, these are hardcoded for now */}}
{{ $tinyw := default "300x" }}
{{ $smallw := default "600x" }}
{{ $mediumw := default "1200x" }}
{{/* resize the src image to the given sizes */}}
{{ .Scratch.Set "tiny" ($src.Resize $tinyw) }}
{{ .Scratch.Set "small" ($src.Resize $smallw) }}
{{ .Scratch.Set "medium" ($src.Resize $mediumw) }}
{{/* add the processed images to the scratch */}}
{{ $tiny := .Scratch.Get "tiny" }}
{{ $small := .Scratch.Get "small" }}
{{ $medium := .Scratch.Get "medium" }}
{{/* only use images smaller than or equal to the src (original) image size */}}
<img srcset='
{{ if ge $src.Width "300" }}
{{ with $tiny.RelPermalink }}{{.}} 300w{{ end }}
{{ end }}
{{ if ge $src.Width "600" }}
{{ with $small.RelPermalink }}, {{.}} 600w{{ end }}
{{ end }}
{{ if ge $src.Width "1200" }}
{{ with $medium.RelPermalink }}, {{.}} 1200w{{ end }}
{{ end }}'
sizes="(max-width:480px) 300px, (max-width:768px) 600px, 1200px" src="{{ $src.RelPermalink }}" alt="{{ .Params.title }}">
I also tried this scenario by removing {{- with .Params.image -}} from the post-card file and changed resources.GetMatch “{{ .Params.image }}” in partial file. Then get this error: at <$src.Resize>: nil pointer evaluating resource.Resource.Resize.
changed GetMatch to .Resources.Match and the error is:
.Params.image.Resize>: can't evaluate field Resize in type string
I don’t think it matters where they are, if you use Match you end up with a slice, not a single image.
If you have blog I personally think each post being self contained in a page bundle with its content images, opengraph image, image used for a listing thumbnail etc is a more fool proof way of doing things.