#
# OpenAFS wiki local preview.
#
# Setup:
#     $ sudo apt-get install ikiwiki python3 xdg-utils
#

IKIWIKI=/usr/bin/ikiwiki
OPEN=/usr/bin/xdg-open
PYTHON=/usr/bin/python3

.PHONY: help
help:
	@echo "targets:"
	@echo "    make preview    to start http server and open browser"
	@echo "    make site       to create local html files for preview"
	@echo "    make clean      to cleanup preview files"

.PHONY: preview
preview: site
	@echo "Starting http server. Press <control>-C to exit."
	(sleep 2; $(OPEN) http://localhost:8000) &
	$(PYTHON) -m http.server --directory .site

.PHONY: site
site: .setup
	$(IKIWIKI) --setup .setup

.PHONY: clean
clean:
	rm -f .setup
	rm -rf .site

.setup: Makefile
	echo "use IkiWiki::Setup::Standard {" >>$@
	echo "    wikiname => 'openafs-wiki'," >>$@
	echo "    srcdir => '.'," >>$@
	echo "    destdir => '.site'," >>$@
	echo "    url => 'http://localhost/openafs-wiki/'," >>$@
	echo "    rcs => ''," >>$@
	echo "    usedirs => 1," >>$@
	echo "    add_plugins => [qw{goodstuff}]," >>$@
	echo "}" >>$@