{{ $is_disabled := .Param "disable_csp" }}
{{ $site_directives := .Site.Params.security.csp.directives }}
{{ if and $site_directives (ne $is_disabled true) }}
  {{ if ge (len $site_directives) 1 }}
    <meta
      http-equiv="Content-Security-Policy"
      content="default-src{{ if $site_directives.defaultsrc }}
        {{- range $site_directives.defaultsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.defaultsrc }} {{ . | safeHTML }}{{ end -}}
      {{ else }} 'none'{{ end }};connect-src{{ if $site_directives.connectsrc }}
        {{- range $site_directives.connectsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.connectsrc }} {{ . | safeHTML }}{{ end -}}
      {{ else }} 'self'{{ end }};font-src{{ if $site_directives.fontsrc }}
        {{- range $site_directives.fontsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.fontsrc }} {{ . | safeHTML }}{{ end -}}
      {{ else }} 'self'{{ end }};media-src{{ if $site_directives.mediasrc }}
        {{- range $site_directives.mediasrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.mediasrc }} {{ . | safeHTML }}{{ end -}}
      {{ else }} 'self'{{ end }};img-src{{ if $site_directives.imgsrc }}
        {{- range $site_directives.imgsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.imgsrc }} {{ . | safeHTML }}{{ end -}}
      {{ else }} 'self' data:{{ end }};script-src{{ if $site_directives.scriptsrc }}
        {{- range $site_directives.scriptsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.scriptsrc }} {{ . | safeHTML }} {{ end -}}
      {{ else }} 'none'{{ end }};style-src{{ if $site_directives.stylesrc }}
        {{- range $site_directives.stylesrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.stylesrc }} {{ . | safeHTML }} {{ end -}}
      {{ else }} 'self' 'unsafe-inline'{{ end }};frame-src{{ if $site_directives.framesrc }}
        {{- range $site_directives.framesrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.framesrc }} {{ . | safeHTML }} {{ end -}}
      {{ else }} 'self'{{ end }};object-src{{ if $site_directives.objectsrc }}
        {{- range $site_directives.objectsrc }} {{ . | safeHTML }}{{ end -}}
        {{- range .Params.security.csp.directives.objectsrc }} {{ . | safeHTML }} {{ end -}}
      {{ else }} 'none'{{ end }};">
  {{ end }}
{{ else if not $is_disabled }}
  <meta http-equiv="Content-Security-Policy" content="default-src 'self' https: 'unsafe-inline' 'unsafe-eval'; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'">
{{ end }}
