Commits

angri  committed 9219355

docs: a simple way to be able to provide a google-analytics key

  • Participants
  • Parent commits 577fdd7

Comments (0)

Files changed (2)

File doc/Makefile

 SPHINXOPTS    =
 SPHINXBUILD   = sphinx-build
 PAPER         =
+GA_TRACKING_ID =
 
 # Internal variables.
 PAPEROPT_a4     = -D latex_paper_size=a4
 PAPEROPT_letter = -D latex_paper_size=letter
 ALLSPHINXOPTS   = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
 
+ifneq ($(strip $(GA_TRACKING_ID)),)
+define GA_LAYOUT_TEMPLATE
+{% extends "!layout.html" %}
+{%- block extrahead %}
+{{ super() }}
+<script type="text/javascript">
+  var _gaq = _gaq || [];
+  _gaq.push(['_setAccount', '$(GA_TRACKING_ID)']);
+  _gaq.push(['_trackPageview']);
+  (function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+  })();
+</script>
+{% endblock %}
+endef
+export GA_LAYOUT_TEMPLATE
+endif
+
+
 .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
 
 help:
 	-rm -rf _build/*
 
 html:
+ifneq ($(strip $(GA_TRACKING_ID)),)
+	@echo "$$GA_LAYOUT_TEMPLATE" > layout.html
 	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html
+	rm layout.html
+else
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html
+endif
 	@echo
 	@echo "Build finished. The HTML pages are in _build/html."
 
 extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage']
 
 # Add any paths that contain templates here, relative to this directory.
-#templates_path = ['_templates']
+templates_path = ['.']
 
 # The suffix of source filenames.
 source_suffix = '.rst'