Prevent Images in originalsize in public

Hi,

i try to resize all images and only deploy the resized versions of them. But i dont get it working.

My Code:

{{ $content := .Inner | strings.TrimSpace }}
{{ $lines := split $content "\n" }}

<div class="imagegrid">

  {{ range $index, $line := $lines }}
  {{ $imgBig := $line | strings.TrimSpace }}
  {{ if $imgBig }}

  {{ $imgFile := $.Page.Resources.GetMatch $imgBig }}
  {{ $img := $imgFile.Resize "1000x q80" }}


  {{ $id := printf "image_%d" (add $index 1) }}
  <div class="imagegrid__item imagegrid__item--large">
    <a id="{{ $id }}_anchor" class="imagegrid_anchor"></a>
    <a class="imagegrid__link" href="#{{ $id }}">
      <img
              src="{{ $img.RelPermalink }}"
              width="{{ $img.Width }}"
              height="{{ $img.Height }}"
              alt=""
              loading="lazy">
    </a>
  </div>

  <div id="{{ $id }}" class="image-lightbox" role="dialog" aria-modal="true">
    <a class="image-lightbox__close" href="#{{ $id }}_anchor" aria-label="Schließen">✕</a>
    <div class="image-lightbox__inner">
      <img
              src="{{ $img.RelPermalink }}"
              width="{{ $img.Width }}"
              height="{{ $img.Height }}"
              alt=""
              loading="lazy">
    </div>
  </div>

  {{ end }}
{{ end }}
</div>

I use it like this in md files:

{{< imagegallery >}}
IMG_2761.jpeg
IMG_2762.jpeg
IMG_2764.jpeg
IMG_2760.jpeg
IMG_2763.jpeg
IMG_2765.jpeg
IMG_2766.jpeg
IMG_2767.jpeg
IMG_2768.jpeg
IMG_2769.jpeg
{{< /imagegallery >}}

The output includes both, the resized version and the original version. The original-path is not in any other output file. –gc dont change this.

Any Ideas on this? Any hint would help me. Thank you very much!

A file in a page bundle is published by default. Use build options to control whether page resources are published. Note that you can set this in the page front matter, or cascade the setting down from an ancestor section, or from the site config.

1 Like