File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ apiVersion : v2
2+ name : klicktipp.common
3+ description : A Helm library chart for KlickTipp common templates
4+ type : library
5+ version : 0.1.0
6+ appVersion : " 1.0.0"
Original file line number Diff line number Diff line change 1+ {{/*
2+ slugify the string to be (k8s) DNS name compatible
3+ */ }}
4+ {{- define " com.klicktipp.slugify-string" -}}
5+ {{- /* 1) Make sure we’re working with a string, and lowercase it */ -}}
6+ {{- $text := . | toString | lower -}}
7+
8+ {{- /* 2) Replace “anything that is NOT a-z or 0-9” (in runs) with a dash */ -}}
9+ {{- $text = regexReplaceAll " [^a-z0-9]+" $text " -" -}}
10+
11+ {{- /* 3) Remove dashes at the start or end */ -}}
12+ {{- $text = trimAll " -" $text -}}
13+
14+ {{- /* 4) Limit to 63 characters, then remove a trailing dash if truncation created one */ -}}
15+ {{- $text = $text | trunc 63 | trimSuffix " -" -}}
16+
17+ {{- /* 5) If nothing is left (e.g. input was only symbols), fail fast */ -}}
18+ {{- if eq $text " " -}}
19+ {{- fail " slugify: input became empty after sanitizing (must contain at least one a-z/0-9)" -}}
20+ {{- end -}}
21+
22+ {{- /* Final: output the slug */ -}}
23+ {{- $text -}}
24+ {{- end -}}
You can’t perform that action at this time.
0 commit comments