-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrastchecker.html
33 lines (33 loc) · 1.32 KB
/
contrastchecker.html
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
{{- /* https://webaim.org/resources/contrastchecker/?fcolor=242424&bcolor=FCFCFC&api */ -}}
{{- $fcolor := .Get "fcolor" | string -}}
{{- $bcolor := .Get "bcolor" | string -}}
{{- $url := printf "%s%s%s%s%s" "https://webaim.org/resources/contrastchecker/?fcolor=" $fcolor "&bcolor=" $bcolor "&api" -}}
{{- with try (resources.GetRemote $url) -}}
{{- with .Err -}}
{{- warnf "%s" . -}}
{{- else with .Value -}}
{{- $json := unmarshal .Content -}}
<table>
<thead>
<tr>
<th>ratio</th>
<th>AA</th>
<th>AALarge</th>
<th>AAA</th>
<th>AAALarge</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ with $json.ratio }}{{ if gt . 4.5 }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
<td>{{ with $json.AA }}{{ if eq . "pass" }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
<td>{{ with $json.AALarge }}{{ if eq . "pass" }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
<td>{{ with $json.AAA }}{{ if eq . "pass" }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
<td>{{ with $json.AAALarge }}{{ if eq . "pass" }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
</tr>
</tbody>
</table>
{{- else -}}
{{- warnf "Unable to get remote resource %q" $url -}}
{{- end -}}
{{- end -}}