-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinkcontrastchecker.html
33 lines (33 loc) · 1.22 KB
/
linkcontrastchecker.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/linkcontrastchecker/?fcolor=242424&bcolor=FCFCFC&lcolor=0A802D&api */ -}}
{{- $fcolor := .Get "fcolor" | string -}}
{{- $bcolor := .Get "bcolor" | string -}}
{{- $lcolor := .Get "lcolor" | string -}}
{{- $number := 4.5 -}}
{{- $url := printf "%s%s%s%s%s%s%s" "https://webaim.org/resources/linkcontrastchecker/?fcolor=" $fcolor "&bcolor=" $bcolor "&lcolor=" $lcolor "&api" -}}
{{- with try (resources.GetRemote $url) -}}
{{- with .Err -}}
{{- warnf "%s" . -}}
{{- else with .Value -}}
{{- $json := unmarshal .Content -}}
<table>
<thead>
<tr>
<th></th>
<th>conformance</th>
<th>ratio</th>
</tr>
</thead>
<tbody>
{{range $index, $element := $json}}
<tr>
<td><strong>{{ $index }}</strong></td>
<td>{{ with $element.conformance }}{{ if eq . "pass" }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
<td>{{ if eq $index "Link to Body Text" }}{{ $number = 3 }}{{ end }}{{ with $element.ratio }}{{ if gt . $number }}✅ {{.}}{{ else }}❌ {{.}}{{ end }}{{ end }}</td>
</tr>
{{ end }}
</tbody>
</table>
{{- else -}}
{{- warnf "Unable to get remote resource %q" $url -}}
{{- end -}}
{{- end -}}