{{- $reportPath := "data/external_links.yaml" -}} {{- $report := dict -}} {{- if reflect.IsMap . -}} {{- with index . "ReportPath" -}} {{- $reportPath = . -}} {{- end -}} {{- with index . "Report" -}} {{- $report = . -}} {{- end -}} {{- else if . -}} {{- $report = . -}} {{- end -}} {{- if eq (len $report) 0 -}} {{- if eq $reportPath "data/external_links.yaml" -}} {{- with index site.Data "external_links" -}} {{- $report = . -}} {{- end -}} {{- else if fileExists $reportPath -}} {{- $report = transform.Unmarshal (readFile $reportPath) -}} {{- end -}} {{- end -}} {{- $sourceLinks := slice -}} {{- with index $report "deadLinks" -}} {{- $sourceLinks = . -}} {{- end -}} {{- if and (eq (len $sourceLinks) 0) (isset $report "links") -}} {{- $sourceLinks = default (slice) (index $report "links") -}} {{- end -}} {{- $links := slice -}} {{- range $sourceLinks -}} {{- $status := "" -}} {{- with index . "status" -}} {{- $status = printf "%v" . -}} {{- end -}} {{- if eq $status "" -}} {{- with index . "code" -}} {{- $status = printf "%v" . -}} {{- end -}} {{- end -}} {{- $links = $links | append (dict "url" (default "" (index . "url")) "status" $status "locations" (default (slice) (index . "locations")) "errorType" (default "" (index . "errorType")) "checkedAt" (default "" (index . "checkedAt")) ) -}} {{- end -}} {{- return (dict "generatedAt" (default "" (index $report "generatedAt")) "entries" (default (dict) (index $report "entries")) "links" $links ) -}}