63 lines
1.9 KiB
HTML
63 lines
1.9 KiB
HTML
{{- $rawURLs := slice -}}
|
|
{{- $currentPage := false -}}
|
|
{{- if reflect.IsMap . -}}
|
|
{{- with .URLs -}}
|
|
{{- $rawURLs = . -}}
|
|
{{- end -}}
|
|
{{- with .CurrentPage -}}
|
|
{{- $currentPage = . -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- $rawURLs = . -}}
|
|
{{- end -}}
|
|
|
|
{{- $urls := slice -}}
|
|
{{- if reflect.IsSlice $rawURLs -}}
|
|
{{- $urls = $rawURLs -}}
|
|
{{- else -}}
|
|
{{- $singleURL := strings.TrimSpace (printf "%v" $rawURLs) -}}
|
|
{{- if ne $singleURL "" -}}
|
|
{{- $urls = slice $singleURL -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $pages := slice -}}
|
|
{{- $seen := dict -}}
|
|
{{- range $urls -}}
|
|
{{- $rawURL := strings.TrimSpace (printf "%v" .) -}}
|
|
{{- if ne $rawURL "" -}}
|
|
{{- $parsedURL := urls.Parse $rawURL -}}
|
|
{{- $path := strings.TrimSpace $parsedURL.Path -}}
|
|
{{- if eq $path "" -}}
|
|
{{- $path = $rawURL -}}
|
|
{{- end -}}
|
|
{{- if not (strings.HasPrefix $path "/") -}}
|
|
{{- $path = printf "/%s" $path -}}
|
|
{{- end -}}
|
|
{{- if not (strings.HasSuffix $path "/") -}}
|
|
{{- $path = printf "%s/" $path -}}
|
|
{{- end -}}
|
|
|
|
{{- $match := false -}}
|
|
{{- $matches := where site.RegularPages "RelPermalink" "eq" $path -}}
|
|
{{- if gt (len $matches) 0 -}}
|
|
{{- $match = index $matches 0 -}}
|
|
{{- else -}}
|
|
{{- $matches = where site.RegularPages "Aliases" "intersect" (slice $path) -}}
|
|
{{- if gt (len $matches) 0 -}}
|
|
{{- $match = index $matches 0 -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- if $match -}}
|
|
{{- $matchedPermalink := $match.RelPermalink -}}
|
|
{{- $isCurrentPage := and $currentPage (eq $matchedPermalink $currentPage.RelPermalink) -}}
|
|
{{- if and (not $isCurrentPage) (not (isset $seen $matchedPermalink)) -}}
|
|
{{- $pages = $pages | append $match -}}
|
|
{{- $seen = merge $seen (dict $matchedPermalink true) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- return $pages -}}
|