mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
yesterday 69f2871e872b8c4c32cabbc6d9c5eed07295b901
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{{- $config := site.Params.ananke.hooks | compare.Default (collections.Dictionary) -}}
{{/* 
 
$config.namespace
$config.ignoreErrors
$config.verbosity
 
*/}}
{{/*
[ananke.hooks]
verbosity = "warning" # debug, info, warning, error
 
@todo add and document hook ignoreErrors setting via config
*/}}
 
{{/*
| Primary | `#AA99FF` | `170, 153, 255` |
| Ananke  | `#FF80BF` | `255, 128, 191` |
| Comment | `#708CA9` | `112, 140, 169` |
| Error   | `#CC7766` | `204, 119, 102` |
| Warning | `#CCCC66` | `204, 204, 102` |
| Info    | `#6ECC66` | `110, 204, 102` |
*/}}
 
{{- $colourPrimary := "\033[38;2;170;153;255m" -}}
{{- $colourAnanke := "\033[38;2;255;128;191m" -}}
{{- $colourComment := "\033[38;2;112;140;169m" -}}
{{- $colourError := "\033[38;2;204;119;102m" -}}
{{- $colourWarning := "\033[38;2;204;204;102m" -}}
{{- $colourInfo := "\033[38;2;110;204;102m" -}}
{{- $colourReset := "\033[0m" -}}
 
{{- $namespace := $config.namespace | compare.Default "ananke" -}}
{{- $severity := .severity | compare.Default "info" -}}
{{- $severity = strings.ToLower $severity -}}
{{- if or (compare.Eq $severity "warnings") (compare.Eq $severity "warn") -}}
  {{- $severity = "warning" -}}
{{- else if or (compare.Eq $severity "errors") (compare.Eq $severity "err") -}}
  {{- $severity = "error" -}}
{{- else if compare.Eq $severity "infos" -}}
  {{- $severity = "info" -}}
{{- end -}}
 
{{- $verbosity := $config.verbosity | compare.Default "error" -}}
{{- $verbosity = strings.ToLower $verbosity -}}
{{- if or (compare.Eq $verbosity "warnings") (compare.Eq $verbosity "warn") -}}
  {{- $verbosity = "warning" -}}
{{- else if or (compare.Eq $verbosity "errors") (compare.Eq $verbosity "err") -}}
  {{- $verbosity = "error" -}}
{{- else if compare.Eq $verbosity "infos" -}}
  {{- $verbosity = "info" -}}
{{- else if not (or (compare.Eq $verbosity "debug") (compare.Eq $verbosity "info") (compare.Eq $verbosity "warning") (compare.Eq $verbosity "error")) -}}
  {{- $verbosity = "error" -}}
{{- end -}}
 
{{- $shouldOutput := false -}}
{{- if compare.Eq $verbosity "debug" -}}
  {{- $shouldOutput = true -}}
{{- else if and (compare.Eq $verbosity "info") (not (compare.Eq $severity "debug")) -}}
  {{- $shouldOutput = true -}}
{{- else if and (compare.Eq $verbosity "warning") (or (compare.Eq $severity "warning") (compare.Eq $severity "error")) -}}
  {{- $shouldOutput = true -}}
{{- else if and (compare.Eq $verbosity "error") (compare.Eq $severity "error") -}}
  {{- $shouldOutput = true -}}
{{- end -}}
 
{{- $colourLevel := $colourInfo -}}
{{- $severityLabel := "INFO" -}}
 
{{- if compare.Eq $severity "warning" -}}
  {{- $colourLevel = $colourWarning -}}
  {{- $severityLabel = "WARN" -}}
{{- else if compare.Eq $severity "error" -}}
  {{- $colourLevel = $colourError -}}
  {{- $severityLabel = "!ERR" -}}
{{- else if compare.Eq $severity "debug" -}}
  {{- $colourLevel = $colourComment -}}
  {{- $severityLabel = "DEBG" -}}
{{- end -}}
 
{{- if $shouldOutput -}}
  {{- if compare.Eq $severity "error" -}}
    {{- fmt.Errorf (fmt.Printf "%s%s%s/%s%s %s%s%s" $colourAnanke $namespace $colourComment $colourLevel $severityLabel $colourComment .message $colourReset) -}}
  {{- else -}}
    {{- fmt.Warnf (fmt.Printf "%s%s%s/%s%s %s%s%s" $colourAnanke $namespace $colourComment $colourLevel $severityLabel $colourComment .message $colourReset) -}}
  {{- end -}}
{{- end -}}