Javascript in blogpost, but not on all sites at the same time?

My approach is to use the content metadata to instruct my footer template to load extra js files. The JS is not part of the content (that’s a presentation concern), so don’t try to marry them in your markdown if you can avoid it.

Example content metadata:

+++
js = ["chart", "dropdown/latest.min"]
+++

At the bottom of the footer template, I have this:

{{- range .Params.js }}
<script src="/js/{{ . }}.js"></script>
{{- end }}
3 Likes