Skip to content

Commit a936505

Browse files
committed
Update feature-state shortcode with dynamic state retrieval
1 parent 65e31b4 commit a936505

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

data/i18n/en/en.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ other = "Until"
151151
[feature_state]
152152
other = "FEATURE STATE:"
153153

154+
[feature_state_kubernetes_label]
155+
other = "Kubernetes"
156+
157+
[feature_state_feature_gate_tooltip]
158+
other = "Feature Gate:"
159+
154160
[feedback_heading]
155161
other = "Feedback"
156162

layouts/shortcodes/feature-state.html

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,56 @@
22
{{ $state := .Get "state" }}
33
{{ $for_k8s_version := .Get "for_k8s_version" | default (.Page.Param "version")}}
44
{{ $is_valid := strings.Contains $valid_states $state }}
5-
{{ if not $is_valid }}
6-
{{ errorf "%q is not a valid feature-state, use one of %q" $state $valid_states }}
7-
{{ else }}
8-
<div style="margin-top: 10px; margin-bottom: 10px;">
9-
<b>{{ T "feature_state" }}</b> <code>Kubernetes {{ $for_k8s_version }} [{{ $state }}]</code>
10-
</div>
5+
{{ $feature_gate_name := .Get "feature_gate_name" }}
6+
7+
<!-- When 'feature_gate_name' parameter is not specified, continue with the values provided. -->
8+
{{ if not $feature_gate_name }}
9+
{{ if not $is_valid }}
10+
{{ errorf "%q is not a valid feature-state, use one of %q" $state $valid_states }}
11+
{{ else }}
12+
<div class="my-2 feature-state-notice feature-{{ $state }}">
13+
<b>{{ T "feature_state" }}</b> <code>{{T "feature_state_kubernetes_label" }} {{ $for_k8s_version }} [{{ $state }}]</code>
14+
</div>
15+
{{ end }}
16+
17+
{{- else -}}
18+
<!-- When 'feature_gate_name' is specified, the following code block extracts the status of the feature gate from the description file. -->
19+
20+
<!-- Set the path for feature gate description files -->
21+
{{- $featureGateDescriptionFilesPath := "/docs/reference/command-line-tools-reference/feature-gates" -}}
22+
23+
<!-- Access the 'English' site and get the feature gate description pages -->
24+
{{- with index (where .Site.Sites "Language.Lang" "eq" "en") 0 -}}
25+
{{- with .GetPage $featureGateDescriptionFilesPath -}}
26+
27+
<!-- Sort Feature gate pages list -->
28+
{{- $sortedFeatureGates := sort (.Resources.ByType "page") -}}
29+
{{- $featureGateFound := false -}}
30+
31+
<!-- Iterate through feature gate files -->
32+
{{- range $featureGateFile := $sortedFeatureGates -}}
33+
{{- $featureGateNameFromFile := $featureGateFile.Params.Title -}}
34+
35+
{{- if eq $featureGateNameFromFile $feature_gate_name -}}
36+
<!-- Extract information from the final stage of the feature gate -->
37+
{{- $currentStage := index $featureGateFile.Params.stages (sub (len $featureGateFile.Params.stages) 1) -}}
38+
{{- with $currentStage -}}
39+
40+
<!-- Display feature state information -->
41+
<div class="my-2 feature-state-notice feature-{{ .stage }}" title="{{ printf "%s %s" (T "feature_state_feature_gate_tooltip") $feature_gate_name }}">
42+
<b>{{ T "feature_state" }}</b> <code>{{T "feature_state_kubernetes_label" }} v{{ .fromVersion }} [{{ .stage }}]</code>
43+
</div>
44+
45+
{{- $featureGateFound = true -}}
46+
{{- end -}}
47+
{{- end -}}
48+
{{- end -}}
49+
50+
<!-- Check if specified feature gate is not found -->
51+
{{- if not $featureGateFound -}}
52+
{{- errorf "Invalid feature gate: '%s' is not recognized or lacks a matching description file in '%s'" $feature_gate_name (print "en" $featureGateDescriptionFilesPath) -}}
53+
{{- end -}}
54+
55+
{{- end -}}
56+
{{- end -}}
1157
{{ end }}

0 commit comments

Comments
 (0)