Debian Codegraph @

docs/layouts/_partials/helpers/funcs/color-from-string.html

raw
1 {{ $colors := slice "slate" "green" "cyan" "blue" }}
2 {{ with .single }}
3 {{ $colors = slice . }}
4 {{ end }}
5
6 {{ $shades := slice 300 400 500 }}
7 {{ if not .dark }}
8 {{ $shades = slice 700 800 }}
9 {{ end }}
10 {{ $hash := (hash.FNV32a .text) }}
11 {{ $i := mod $hash (len $colors) }}
12 {{ $j := mod $hash (len $shades) }}
13 {{ $color := index $colors $i }}
14 {{ $shade1 := index $shades $j }}
15 {{ $shade2 := 0 }}
16 {{ $shade3 := 0 }}
17 {{ if gt $shade1 500 }}
18 {{ $shade2 = math.Min (sub $shade1 500) 100 | int }}
19 {{ $shade3 = sub $shade1 100 }}
20 {{ else }}
21 {{ $shade2 = math.Max (add $shade1 500) 700 | int }}
22 {{ $shade3 = add $shade1 200 }}
23 {{ end }}
24 {{ $res := dict "color" $color "shade1" $shade1 "shade2" $shade2 "shade3" $shade3 }}
25 {{ return $res }}