nicokaiser / hugo-theme-gallery

Gallery Theme for Hugo
https://nicokaiser.github.io/hugo-theme-gallery/
MIT License
368 stars 112 forks source link

Deduplicate images between `content` and `public` #90

Closed CapacitorSet closed 1 month ago

CapacitorSet commented 1 month ago

I noticed that a copy of every image is made from content to public, along with lower-resolution versions. For example:

$ md5sum content/redacted/IMG_20221004_135139.jpg public/redacted/IMG_20221004_135139*
aebafbf340ab8ba2abecb9879da95e00  content/redacted/IMG_20221004_135139.jpg
a59cce742ff3ec49d9be2c736705f6bc  public/redacted/IMG_20221004_135139_hu13918357761984099453.jpg
5ab68cfb2032f24980a8c45b85a9791b  public/redacted/IMG_20221004_135139_hu14619862059240754237.jpg
cc564cc89f5510315acf1d6950e69cc8  public/redacted/IMG_20221004_135139_hu1762357654209761686.jpg
aebafbf340ab8ba2abecb9879da95e00  public/redacted/IMG_20221004_135139.jpg

Because photos are duplicated, the project directory takes twice as much space. Would it be possible to hard link the files instead, or add an option to skip the copy entirely?

nicokaiser commented 1 month ago

I don't think this is possible with Hugo. Because of the way Hugo works, the files in public need to be copies, so regardless what happens in content the files need to stay the same (and thus, hardlinks will not work).

Skipping the files altogether neither works, because the original files are referenced in the rendered site, they are opened when you click and download the photos.

So unfortunately there is no elegant solution for this (other than using a deduplicating filesystem and hoping for the deduplication to help here).

CapacitorSet commented 1 month ago

Skipping the files altogether neither works, because the original files are referenced in the rendered site, they are opened when you click and download the photos.

I know, I was thinking of an option that would also remove the "download" feature. Although I do see how it would be an edge case.

Let's say I can serve the raw images from another HTTP URL - what files should I change in my local theme to make the download button link to that and skip the copy? Or does Hugo just copy the files in content unconditionally?

nicokaiser commented 1 month ago

I don't know if this is even possible in Hugo. Currently Hugo copies the files unconditionally. Maybe you could add a post-build script which removes the original images, but if they are referenced from the built HTML (like in the Download feature or the href of the images (which need to be replaced by something like $thumbnails.RelPermalink then) you might end up with many broken links.