diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index 21e68bd2..0b6f04ff 100644 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -25,5 +25,7 @@ maxAge = -1 github_repo = "https://github.com/nginxinc/nginx-hugo-theme" github_subdir = "exampleSite" enable_last_modified = true - disable_coveo = true - coveo_search_redirect = "/search.html" \ No newline at end of file + coveo_search_redirect = "/search.html" + [params.featureFlags] + disable_coveo = true + disable_qualtrics = true \ No newline at end of file diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 4319efc2..c8302e0c 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -38,7 +38,8 @@

{{ .Title }}

{{ end }} {{ partial "version-list" . }} - {{ if .Site.Params.enable_qualtrics }} + {{ $qualtricsEnabled := partial "get-feature-flags.html" "disable_qualtrics" }} + {{ if $qualtricsEnabled }} {{ partial "qualtrics-feedback.html" }} {{ end }} diff --git a/layouts/partials/get-feature-flags.html b/layouts/partials/get-feature-flags.html new file mode 100644 index 00000000..e858be0d --- /dev/null +++ b/layouts/partials/get-feature-flags.html @@ -0,0 +1,16 @@ +{{- /* Extract parameter with defaults and validation */ -}} +{{- $featureName := . -}} +{{- $featureFlags := site.Params.featureflags -}} +{{- $featureFlagVal := (index $featureFlags $featureName) | default false -}} + +{{- if ne (printf "%T" $featureFlagVal) "bool" -}} + {{ errorf "Expected type of feature flag param %s to be boolean." $featureName }} +{{- end -}} + +{{- $param := index $featureFlagVal -}} +{{- $result := false -}} +{{- if not (eq $param true) -}} + {{- $result = true -}} +{{- end -}} + +{{- return $result -}} \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 0fb4555c..9ab8f2d1 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -12,7 +12,8 @@ {{ if ( not ( in .Site.Params.buildtype "package" ) ) }} - {{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }} + {{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }} + {{ if $coveoEnabled }} diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html index 5f621012..4fac6478 100644 --- a/layouts/partials/meta.html +++ b/layouts/partials/meta.html @@ -37,11 +37,13 @@ {{ end }} - +{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }} +{{ $qualtricsEnabled := partial "get-feature-flags.html" "disable_qualtrics" }} {{/* set custom CSP to load styles and scripts with special handling for GTM scripts (requires unsafe-inline) and Dev Portal page(s) (requires 'unsafe-eval') */}} {{/* end */}} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index f02fedb8..eba49ca6 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -17,7 +17,8 @@ {{ end }} -{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }} +{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }} +{{ if $coveoEnabled }} {{ end }} diff --git a/layouts/partials/styles.html b/layouts/partials/styles.html index 99962124..5abbeec2 100644 --- a/layouts/partials/styles.html +++ b/layouts/partials/styles.html @@ -8,7 +8,8 @@ -{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }} +{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }} +{{ if $coveoEnabled }} {{ partial "coveo-atomic.html" .}}