Attempt to implement a feature flag to toggle CSS layers on and off

This commit is contained in:
Eryn Wells 2023-05-20 08:30:35 -07:00
parent 4f63fab916
commit 4cedd992b8
4 changed files with 29 additions and 9 deletions

View file

@ -2,3 +2,6 @@ twitter: erynofwales
github: erynofwales github: erynofwales
instagram: erynofwales instagram: erynofwales
description: Home page of Eryn Rachel Wells description: Home page of Eryn Rachel Wells
flags:
cssLayers: development

View file

@ -0,0 +1,4 @@
{{- $enabled := partial "flag_is_enabled.html" "cssLayers" -}}
{{ if $enabled -}}{{ printf "@layer %s {" . }}{{- end }}
{{ .Inner }}
{{ if $enabled -}}{{ `}` }}{{- end }}

View file

@ -17,15 +17,17 @@
</tbody> </tbody>
{{ end }} {{ end }}
</table> </table>
{{ if gt (len site.Params.flags) 0 -}} {{ with site.Params.flag -}}
<h4>Flags</h4> {{- if gt (len .) 0 -}}
<table> <h4>Flags</h4>
<tbody> <table>
{{ range $flag, $value := site.Params.flags }} <tbody>
<tr><td>{{ $flag }}</td><td>{{ $value }}</td></tr> {{ range $flag, $value := site.Params.flags }}
{{ end }} <tr><td>{{ $flag }}</td><td>{{ $value }}</td></tr>
</tbody> {{ end }}
</table> </tbody>
</table>
{{- end -}}
{{- end }} {{- end }}
</details> </details>
</div> </div>

View file

@ -0,0 +1,11 @@
{{ $result := false }}
{{ with $flag := index . site.Params.flags }}
{{ if hugo.IsProduction }}
{{ $result = in (slice "yes" "true" "production" "development") $flag }}
{{ else }}
{{ $result = in (slice "yes" "true" "development") $flag }}
{{ end }}
{{ end }}
{{ return $result }}