Skip to content

Commit cf927a1

Browse files
reixdRainer 'rei' SchuthCopilot
authored
Add Helm library chart with slugify template function for KlickTipp (#37)
Co-authored-by: Rainer 'rei' Schuth <rainer.schuth@digital-results-international.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 180b726 commit cf927a1

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

charts/klicktipp.common/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 -}}

0 commit comments

Comments
 (0)