Skip to content

Commit fd921f2

Browse files
authored
Partial: Add new partial to handle feature flags + update usages (#425)
1 parent 230ddf2 commit fd921f2

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

exampleSite/hugo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ maxAge = -1
2525
github_repo = "https://github.com/nginxinc/nginx-hugo-theme"
2626
github_subdir = "exampleSite"
2727
enable_last_modified = true
28-
disable_coveo = true
29-
coveo_search_redirect = "/search.html"
28+
coveo_search_redirect = "/search.html"
29+
[params.featureFlags]
30+
disable_coveo = true
31+
disable_qualtrics = true

layouts/_default/single.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ <h1>{{ .Title }}</h1>
3838
{{ end }}
3939

4040
{{ partial "version-list" . }}
41-
{{ if .Site.Params.enable_qualtrics }}
41+
{{ $qualtricsEnabled := partial "get-feature-flags.html" "disable_qualtrics" }}
42+
{{ if $qualtricsEnabled }}
4243
{{ partial "qualtrics-feedback.html" }}
4344
{{ end }}
4445
</article>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- /* Extract parameter with defaults and validation */ -}}
2+
{{- $featureName := . -}}
3+
{{- $featureFlags := site.Params.featureflags -}}
4+
{{- $featureFlagVal := (index $featureFlags $featureName) | default false -}}
5+
6+
{{- if ne (printf "%T" $featureFlagVal) "bool" -}}
7+
{{ errorf "Expected type of feature flag param %s to be boolean." $featureName }}
8+
{{- end -}}
9+
10+
{{- $param := index $featureFlagVal -}}
11+
{{- $result := false -}}
12+
{{- if not (eq $param true) -}}
13+
{{- $result = true -}}
14+
{{- end -}}
15+
16+
{{- return $result -}}

layouts/partials/header.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
</div>
1313
{{ if ( not ( in .Site.Params.buildtype "package" ) ) }}
1414
<!-- Mobile button -->
15-
{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }}
15+
{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }}
16+
{{ if $coveoEnabled }}
1617
<label class="header__search--mobile--search--button"for="search-standalone-header-panel" data-testid="header__search--mobile--search--button">
1718
{{ partial "lucide" (dict "context" . "icon" "search") }}
1819
</label>

layouts/partials/meta.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
<meta http-equiv="last-modified" content="{{ .Page.Lastmod.Format "02/01/2006" }}" />
3838
{{ end }}
3939

40-
40+
{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }}
41+
{{ $qualtricsEnabled := partial "get-feature-flags.html" "disable_qualtrics" }}
4142
{{/* 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') */}}
4243
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'
43-
https://consent.trustarc.com/ https://mktg.tags.f5.com/basic/prod/utag.sync.js
44-
{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }} https://static.cloud.coveo.com/ {{ end }}
44+
https://consent.trustarc.com/
45+
https://mktg.tags.f5.com/basic/prod/utag.sync.js
46+
{{ if $coveoEnabled }}https://static.cloud.coveo.com/{{ end }}
4547
https://*.f5.com/
4648
https://*.netlify.app https://gist.github.com
4749
https://tag.demandbase.com/pscSDsz4.min.js
@@ -54,8 +56,8 @@
5456
https://cdn.bizible.com/xdc.js
5557
https://f5networksglobalprod.122.2o7.net/
5658
https://f5networksnginxdocs.122.2o7.net/
57-
https://*.siteintercept.qualtrics.com/SIE/?Q_ZID=*
58-
https://siteintercept.qualtrics.com/
59+
{{ if $qualtricsEnabled }}https://*.siteintercept.qualtrics.com/SIE/?Q_ZID=*{{ end }}
60+
{{ if $qualtricsEnabled }}https://siteintercept.qualtrics.com/{{ end }}
5961
{{ if in .Params.doctypes "devportal" }} 'unsafe-eval' {{end}};
6062
worker-src 'self' blob:">
6163
{{/* end */}}

layouts/partials/scripts.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
{{ end }}
1818

1919
<!-- Coveo Atomic -->
20-
{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }}
20+
{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }}
21+
{{ if $coveoEnabled }}
2122
<script
2223
type="module"
2324
src="https://static.cloud.coveo.com/atomic/v3.19.0/atomic.esm.js"
@@ -40,7 +41,6 @@
4041
{{ $.Scratch.Set "coveoSc" $coveo}}
4142
{{ $secureCoveo := $.Scratch.Get "coveoSc" | minify | fingerprint "sha512" }}
4243

43-
4444
<script src="{{ $secureCoveo.RelPermalink }}" integrity="{{ $secureCoveo.Data.Integrity }}"type="text/javascript"></script>
4545
{{ end }}
4646

layouts/partials/styles.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<link href="{{ $cssHighlight.RelPermalink }}" rel="stylesheet" type="text/css">
99

1010
<!-- load CSS Atomic CSS -->
11-
{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }}
11+
{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }}
12+
{{ if $coveoEnabled }}
1213
<link
1314
rel="stylesheet"
1415
href="https://static.cloud.coveo.com/atomic/v3.19.0/themes/coveo.css"

layouts/search/single.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{ define "main" }}
2-
{{ if not (or (eq .Site.Params.disable_coveo true) (eq .Site.Params.disable_coveo "true")) }}
2+
{{ $coveoEnabled := partial "get-feature-flags.html" "disable_coveo" }}
3+
{{ if $coveoEnabled }}
34
<section class="search no-sidebar">
45
{{ partial "coveo-atomic.html" .}}
56
</section>

0 commit comments

Comments
 (0)