{{ $redirectsExist := false }}

{{- range $p := .Site.Pages -}}
  {{- if isset $p.Params "redirects" -}}
    {{- range .Params.redirects -}}
      {{- $redirectsExist = true -}}
      {{- $url := . -}}
      {{- $hasLeadingSlash := eq (substr $url 0 1) "/" -}}
      {{- $hasTrailingSlash := eq (substr $url -1 1) "/" -}}
      {{- $output := $url -}}
      {{- if not $hasLeadingSlash -}}
        {{- $output = print "/" $output -}}
      {{- end }}
      {{- if not $hasTrailingSlash -}}
        {{- $output = print $output "/" -}}
      {{- end -}}
      {{- printf "%s %s;\n" $output $p.RelPermalink -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

{{- if not $redirectsExist -}}
  {{- print "# no redirects" -}}
{{- end -}}
