Debugging #
In hugo templates you can detect whether you are running in draft mode or not by checking:
{{ $isDev := .Site.BuildDrafts }}
One nice feature of this is that you do not have to actually change any code when going back and forth between production and development environments. All the code stays the same and just behaves slightly differently when changing modes.
The check looks like this:
{{ if $isDev }}
{{ warnf "DX DEBUG: debug message print to console" }}
{{ end }}
Another option is to include something like this in your
extend-head-uncached.html
partial (in `layouts/partials’):
{{/* expose a tiny JS flag only in dev so our scripts can check it */}}
{{ if $isDev }}<script>window.__DX_DEV__=true;</script>{{ end }}
which will create a global JS flag __DX_DEV__
that you can check in your
scripts. This would go at the top of you javascript file:
var __DEV__ = (typeof window !== 'undefined' && window.__DX_DEV__ === true);
if (__DEV__) { try { console.log('dx: photo.js loaded'); } catch(e){} }