I store big images (in their original format and size) to process them and deliver lower qualities and smaller sizes where I need them.
But the unprocessed, original jpgs get put into the /public folder although I don’t use them on the page.
Since they are pretty big, I would love to get by without having them copied to the public folder but only have the processed versions.
Is there a way to do it?
This is my file structure:
content/
├── site1.md
├── site2.md
├── site3.md
├── site4.md
└── media
| └── index.md
└── img
| ├── img0.jpg
| └── img00.jpg
├── folder1
| ├── image1.jpg
| ├── image2.jpg
| └── image3.jpg
├── folder2
| ├── image1.jpg
| ├── image2.jpg
| └── image3.jpg
├── folder3
| ├── image1.jpg
| ├── image2.jpg
| └── image3.jpg
The code on my site:
–
layouts/photo/create.html
<!-- config -->
{{- $imageBox_1x := ( print .Site.Params.images.boxsize "x" .Site.Params.images.boxsize ) -}}
{{- $imageBox_2x := ( print (mul .Site.Params.images.boxsize 2) "x" (mul .Site.Params.images.boxsize 2) ) -}}
<!-- embed -->
{{- $name := .Params.img -}}
{{- $images := (.Site.GetPage "page" "media").Resources.Match (print "img/" $name) -}}
{{- range $image := $images -}}
{{- $image_1x := ($image.Fit $imageBox_1x ) -}}
{{- $image_2x := ($image.Fit $imageBox_2x ) -}}
{{- $imagedict := (dict "url_1x" $image_1x.RelPermalink "url_2x" $image_2x.RelPermalink "height" $image_1x.Height "width" $image_1x.Width ) -}}
{{- $.Scratch.Add "images" (slice $imagedict) -}}
{{- end -}}
–
layouts/photo/embed.html
{{- .Render "create" -}}
<div id="photo-container">
{{ range $key, $data := ( $.Scratch.Get "images" ) }}
<img class="fade"
alt = "{{ .Params.title }}"
width="{{ $data.width }}px"
height="{{ $data.height }}px"
src="{{ $data.url_1x }}"
srcset="{{ $data.url_1x }} 1x, {{ $data.url_2x }} 2x" >
{{ end }}
</div>
–
layouts/photo/thumb.html
<!-- config -->
{{- $thumbnailBox_1x := ( print .Site.Params.thumbs.boxsize "x" .Site.Params.thumbs.boxsize ) -}}
{{- $thumbnailBox_2x := ( print (mul .Site.Params.thumbs.boxsize 2) "x" (mul .Site.Params.thumbs.boxsize 2) ) -}}
{{- $thumbnailQuality := .Site.Params.thumbs.quality -}}
<!-- thumb -->
{{- with .Params.thumb | default .Params.img -}}
{{- $.Scratch.Set "thumb" . -}}
{{- end -}}
{{- $thumb := (.Site.GetPage "page" "media").Resources.GetMatch (print "img/" ( .Scratch.Get "thumb" ) ) -}}
{{- $thumb_1x := ($thumb.Fit (print $thumbnailBox_1x " q" $thumbnailQuality)) -}}
{{- $thumb_2x := ($thumb.Fit (print $thumbnailBox_2x " q" $thumbnailQuality)) -}}
{{- .Scratch.Set "thumbnail_1x" $thumb_1x.RelPermalink -}}
{{- .Scratch.Set "thumbnail_2x" $thumb_2x.RelPermalink -}}
{{- .Scratch.Set "thumbnail_width" $thumb_1x.Width -}}
{{- .Scratch.Set "thumbnail_height" $thumb_1x.Height -}}
and in the partial:
<div id="modal-content" class="loading">
<div class="loadstatus blink" hidden="hidden">
<p>#loading</p>
</div>
{{- if .IsPage -}}
{{- if isset .Params "type" -}}
{{- .Render "embed" -}}
{{- end -}}
{{- end -}}
</div>
Is there a way to not have the originals copied to public even though I don’t need/use them?
Is there another way / a more simple way to do what I’m doing?
I would like to keep the site itself and it’s resources in separate folders. Since I don’t only have “photo” types, I would prefer to not hav folders for some sites and files for others.
Am I doing it wrong?
(I’m on 0.37)