.DEFAULT_GOAL := help
.PHONY: clear live site image push run help

## clear = Remove cache directories
clear:
	rm -rf __pycache__ .cache site

## live = Run zensical with live-reloading on http://localhost:8801
live: clear
	@echo "*** Wait until container starts and open http://localhost:8801 to see live preview"
	@docker stop iptv-docs-dev 2>/dev/null; \
	docker run \
		--rm \
		--interactive \
		--tty \
		--env PYTHONPATH=/docs \
		--publish 8801:8801 \
		--volume ${PWD}:/docs \
		--name iptv-docs-dev \
		zensical/zensical:latest

## site = Build a local static site
site: clear
	@echo "*** Wait until zensical finish"
	@docker stop iptv-docs-dev 2>/dev/null; \
	docker run \
		--pull always \
		--rm \
		--env PYTHONPATH=/docs \
		--volume ${PWD}:/docs \
		--name iptv-docs-dev \
		zensical/zensical:latest \
		build \
		--clean

## image = Build a docker image
image:
	@docker build --tag git.axenov.dev/iptv/iptv-docs:latest:latest .

## run = Run docker container from image built with `make image` on http://localhost:8802
run:
	@echo "*** Wait until container starts and open http://localhost:8802 to see ready static website"
	@docker stop iptv-docs 2>/dev/null; \
	docker run \
		--rm \
		--publish 8802:80 \
		--name iptv-docs \
		git.axenov.dev/iptv/iptv-docs:latest:latest

# push = Push docker image built with `make image` to git.axenov.dev
push:
	@docker login git.axenov.dev; \
	docker push git.axenov.dev/iptv/iptv-docs:latest:latest

## help = Show this message and exit (default)
help: Makefile
	@echo "Available recipes:"
	@sed -n 's/^##/    /p' $< | column -t -s '='
