# vim: set ft=make :


prepare-docs: ## install prerequisites for static docs site only
	pipenv install

.PHONY: prepare-docs
prepare: prepare-docs

.PHONY: sync-docs-internal
sync-docs-internal:
	@>&2 echo "ERROR: not implemented"
	exit 1

.PHONY: clean-docs
clean-docs: ## remove generated static docs site
	rm -fr $(BUILD_DOCS_DIR) 

.PHONY: clean-docs
clean: clean-docs

build-docs-pdf:  ## build pdf docs only
	mkdir -p $(BUILD_DOCS_DIR)
	mkdir -p $(CACHE_DOCS_DIR)
	./utils/docs/build_combined.sh $(DOCS_DIR) $(CACHE_DOCS_DIR)/combined.md
	./utils/docs/build_metadata.sh mkdocs.yml $(CACHE_DOCS_DIR)/metadata.yml
	./utils/docs/build_pdf.py $(CACHE_DOCS_DIR)/metadata.yml $(CACHE_DOCS_DIR)/combined.md $(BUILD_DOCS_DIR)/docs.pdf
	# rm -f $(BUILD_DOCS_DIR)/combined.pdf
	# PYTHONUTF8=1 \
	# 	ENABLE_PDF_EXPORT=1 \
    #      pipenv run mkdocs build \
    #         --site-dir $(BUILD_DOCS_DIR)
	# pdftk \
	# 	$$(find -L $(BUILD_DOCS_DIR) -name *.pdf -not -name index.pdf |sort ) \
    #     cat output $(BUILD_DOCS_DIR)/docs.pdf

.PHONY: build-docs-pdf
build-docs: build-docs-pdf

.PHONY: build-docs-html
build-docs-html:  ## build static docs site only
	mkdir -p $(BUILD_DOCS_DIR)
	pipenv run mkdocs build \
		--site-dir $(BUILD_DOCS_DIR)

build-docs: build-docs-html

build: build-docs

.PHONY: watch-docs-internal
watch-docs-internal:
	pipenv run mkdocs serve --dev-addr 0.0.0.0:$(DOCS_PORT)

.PHONY: watch-docs
watch-docs: ## run development server for static docs site
	pipenv run honcho start watch-docs watch-toc

build-pdf: build-docs-pdf ## build docs as PDF files
build-html: build-docs-html ## build docs as HTML files
build-docs: build-docs-pdf build-docs-html  ## build only docs as PDF and HTML

.PHONY: serve-docs
serve-docs: watch-docs