Question

I used the pelican-quickstart to create a static website and this comes with a default pelicanconf and publishconf. I have a GOOGLE_ANALYTICS variable in my publishconf, but when I publish my static page in Github Pages, using this snippet:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS }}']);
_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>

, _setAccount becomes empty string.

Should I move GOOGLE_ANALYTICS from publishconf to pelicanconf? What's the difference between them?

Was it helpful?

Solution

As the person who bifurcated the Pelican settings file in the first place, I recommend thinking of two primary modes of operation: local development and production deployment (i.e., pelicanconf.py and publishconf.py, respectively).

Moving GOOGLE_ANALYTICS from publishconf.py to pelicanconf.py is not recommended. When developing locally, settings for things like Google Analytics and Disqus are deliberately left out of pelicanconf.py by design. Including those settings in local testing can have adverse effects: inaccurate site statistics, spurious comment threads, and other unanticipated side effects.

When it is time to publish your site, then of course you want those settings to be included. The way to do that is to ensure your publishconf.py is being referenced at publish time:

pelican content -s publishconf.py

If you're using either the Fabric or Make automation framework that "wraps" the pelican command, you could instead use:

fab publish

... or ...

make publish

I recommend taking a good look at precisely how you are publishing your site, ensuring that the appropriate settings file is being used during local development and production deployment, respectively.

OTHER TIPS

What you define in publishconf.py overrides the same definitions in pelicanconf.py.
But notice that publishconf.py is only used in two cases:

  1. When you use make publish (or one of the other make commands) to generate your site.
  2. When you explicitly specify it as the config file to be used (i.e. pelican -s publishconf.py content_dir).

So if you generate your site with the pelican command, and not explicitly specify your config file, only pelicanconf.py will be used; thus you will need the GOOGLE_ANALYTICS variable to appear there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top