#!/usr/bin/make -f

export PYBUILD_NAME=bayesian-optimization

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_installdocs:
	cp README.md docsrc/

	https_proxy='127.0.0.1:9' http_proxy='127.0.0.1:9' sphinx-build -b html docsrc build/sphinx/html

	# Replace require.js URLs with local paths
	find -type f -name "*.html" -exec sed -i 's|https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js|/usr/share/javascript/requirejs/require.min.js|g' {} +

	# Replace tex-mml-chtml.js URLs with local paths
	find -type f -name "*.html" -exec sed -i 's|https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js|/usr/share/nodejs/mathjax-full/components/src/tex-mml-chtml/tex-mml-chtml.js|g' {} +

	#Remove privacy-breach URLs that cause warnings
	find -type f -name "*.html" -exec sed -i 's|https://github.com|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://codecov.io|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://img.shields.io|(URL removed)|g' {} +
	find -type f -name "*.html" -exec sed -i 's|https://raw.githubusercontent.com|(URL removed)|g' {} +

	dh_installdocs -ppython-bayesian-optimization-doc --doc-main-package=python-bayesian-optimization-doc build/sphinx/html

	rm -f docsrc/README.md

	dh_installdocs
