VERSION := $(shell git rev-parse --abbrev-ref HEAD)
GOBIN = $(GOPATH)/bin
HUGO_BIN = $(GOBIN)/hugo
OPENRING_BIN = $(GOBIN)/openring

serve: assets
	./hugo server -D --log -w --bind 0.0.0.0

new-post:
	@./hugo new posts/$(TITLE).md

build: public
	docker build -t vdhsn/blog:${VERSION} -f Dockerfile .

publish: clean build
	docker push vdhsn/blog:${VERSION}

test-publish: build
	docker run -it -p 8080:80 vdhsn/blog:${VERSION}

docker-build-dev:
	@docker build --build-arg='VERSION=0.62.0' -t hugo -f Dockerfile.dev .

deploy:
	 kubectl rollout restart deployment blog

assets: ./assets/css/syntax.css ./layouts/partials/openring.out.html

clean:
	@rm -rf ./public ./resources ./assets/css/syntax.css ./layouts/partials/openring.out.html

.PHONY: serve new-post build publish test-publish docker-build-dev assets clean deploy

$(HUGO_BIN):
	@go get -u --tags extended -v github.com/gohugoio/hugo

$(OPENRING_BIN):
	@go get -u git.sr.ht/~sircmpwn/openring

./assets/css/syntax.css:
	hugo gen chromastyles --style=solarized-dark256 > assets/css/syntax.css

./layouts/partials/openring.out.html: $(OPENRING_BIN)
	$(OPENRING_BIN) \
	  -s https://drewdevault.com/feed.xml \
	  -s https://dave.cheney.net/feed/atom \
	  -s https://blog.benjojo.co.uk/rss.xml \
	  -s https://tech.davis-hansson.com/index.xml \
	  < ./assets//openring.in.html \
	  > ./layouts/partials/openring.out.html

public: ./assets/css/syntax.css ./layouts/partials/openring.out.html
	hugo --minify --gc

