# This project depends on a static site generator to translate markdown
# files into a documention website.
#
# This generator is called "hugo", and can be found at:
#   https://github.com/gohugoio/hugo.
#
# This Makefile helps abstract away the specifics of working with hugo,
# so that we can focus on writing great documentation.

# This is the directory that will hold the hugo binary.
BIN_DIR := $(CURDIR)/bin

# The version of hugo to install.
HUGO_VERSION := v0.86.0
HUGO         := $(BIN_DIR)/hugo-$(HUGO_VERSION)

# Removes generated static assets from the working directory.
clean:
	@ rm -rf $(PUBLISH_DIR)
.PHONY: clean

# Runs the development server so you can make changes and immediately
# see the results.
# The same as the 'dev' target!
changes: dev
.PHONY: changes

# Runs the development server so you can make changes and immediately
# see the results.
dev: $(HUGO)
	@ (sleep 1 && open "http://localhost:1313"  &); $(HUGO) server --disableFastRender --baseURL=""
.PHONY: dev

build: $(HUGO) clean
	$(HUGO) -d $(PUBLISH_DIR)
.PHONY: build

ifeq ($(strip $(JENKINS_HOME)),)

publish:
	echo "Publishing only allowed from Jenkins."

else

PUBLISH_PATH=$(CURDIR)/public
BIN=$(CURDIR)/_bin
hugo := $(BIN)/hugo

publish: $(HUGO)
	./scripts/deploy.sh $(HUGO) $(PUBLISH_PATH)

endif

# Uses a generated script to download the specified version of the binary
# appropriate for your development platform.
$(HUGO):
	@ echo "Installing hugo ($(HUGO_VERSION)), a static website generator..."
	@ $(CURDIR)/scripts/godownloader-hugo.sh -b $(BIN_DIR) $(HUGO_VERSION)
