Js
Updated: September 28, 2024
Locations to place JS files for hugo site.
// content metadata
+++
js = ["chart", "dropdown/latest.min"]
+++
// bottom of footer template
{{- range .Params.js }}
<script src="/js/{{ . }}.js"></script>
{{- end }}
For page level scripts, you can seperate them from sidewide. (w/r/t seperation of concerns)
<!--All the other stuff in you base template-->
<!-- Somewhere around your footer -->
...
<script src="/js/scrip-that-runs-everywhere"></script>
{{block "addscripts" . }}
{{end}}
then in layout page (page level script)
...
{{define "addscripts"}}
<script src="/scripts/script-only-for-this-type-of-layout.js"></script>
{{end}}