1{{- $href := .page.RelPermalink -}}
2{{- if and (eq hugo.Environment "offline") (hasSuffix $href "/") -}}
3 {{- $href = printf "%sindex.html" $href -}}
4{{- end -}}
5{{- with .from -}}
6 {{- $directory := .RelPermalink -}}
7 {{- if not (hasSuffix $directory "/") -}}{{- $directory = path.Dir $directory -}}{{- end -}}
8 {{- $prefix := "" -}}
9 {{- range split (trim $directory "/") "/" -}}{{- if . -}}{{- $prefix = printf "%s../" $prefix -}}{{- end -}}{{- end -}}
10 {{- $href = printf "%s%s" ($prefix | default "./") (strings.TrimPrefix "/" $href) -}}
11{{- else -}}
12 {{- $href = $href | relURL -}}
13{{- end -}}
14{{- return $href -}}