# Requires imagick

gallery_name="Decrunch 2117"
foto_path=../../www/decrunch.org/2117/foto/katod
zip_name=2117
edition=2117
date=2-4 VI 2117
author_link=//fb.me/katodmusic
author_name=Katod
img_full_dir=/2117/foto/katod
img_thumb_dir=thumb
gallery_opts=edition date gallery_name author_name author_link zip_name img_thumb_dir img_full_dir

dir_guard=@mkdir -p $(@D)

$(foto_path)/thumb/%.jpg: $(foto_path)/%.jpg
	$(dir_guard)
	@python thumbnailer.py $^

$(foto_path)/$(zip_name).zip: $(foto_path)
	cd $(dir $(foto_path)); \
		zip $(notdir $@) $(addprefix $(notdir $(foto_path))/,$(notdir $(wildcard $(foto_path)/*.jpg)))

thumb: $(addprefix $(foto_path)/thumb/, $(notdir $(wildcard $(foto_path)/*.jpg)))

build/gallery.yaml: thumb
	@echo > $@
	@$(foreach name,$(gallery_opts),echo $(name): $($(name)) >> $@;)
	@echo 'pictures:' >> $@
	@\ls -1 $(foto_path)/thumb | sed 's/\(.*\)/  - "\1"/' >> $@

$(foto_path)/index.html: build/gallery.yaml gallery.j2
	@j2 -f yaml gallery.j2 $< > $@

all: $(foto_path)/index.html thumb