#!/usr/bin/make -f

%:
	dh $@ --buildsystem R

execute_after_dh_installdocs:
	for html in `find debian -name "*.html"` ; do \
	    echo $${html}; sed -i \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/12.1.5/js/smooth-scroll.min.js#file:///usr/lib/R/site-library/visNetwork/smooth-scroll/smooth-scroll.js#g' \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/.*/css/bootstrap\.min\.css#file:///usr/share/javascript/bootstrap/css/bootstrap.min.css#g' \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/.*/js/bootstrap.min.js#file:///usr/share/javascript/bootstrap/js/bootstrap.min.js#g' \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/jquery/.*/jquery.min.js#file:///usr/share/javascript/jquery/jquery.min.js#g' \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/Tipue-Search/5.0.0/tipuesearch.min.js#file:///usr/lib/R/site-library/visNetwork/tipue-search/tipuesearch.js#g' \
		-e 's#https://cdnjs.cloudflare.com/ajax/libs/Tipue-Search/5.0.0/tipuesearch.css#file:///usr/lib/R/site-library/visNetwork/tipue-search/tipuesearch.css#g' \
		-e '/\/oss.maxcdn.com\/html5shiv\//d' \
		-e '/\/oss.maxcdn.com\/respond\//d' \
		    $${html} ; \
	done

execute_before_dh_auto_configure:
	rm -Rf inst/htmlwidgets/lib/fontawesome_4.7.0
	ln -s /usr/share/fonts-font-awesome/ inst/htmlwidgets/lib/fontawesome_4.7.0

execute_after_dh_auto_install:
	rm -Rf debian/r-cran-visnetwork/usr/lib/R/site-library/visNetwork/htmlwidgets/lib/fontawesome_4.7.0
	ln -s /usr/share/fonts-font-awesome/ debian/r-cran-visnetwork/usr/lib/R/site-library/visNetwork/htmlwidgets/lib/fontawesome_4.7.0
	find debian/r-cran-visnetwork -name 'LICENSE*' -delete
