forked from gooddata/gooddata-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseUrlBreadcrumbs.html
More file actions
30 lines (25 loc) · 855 Bytes
/
parseUrlBreadcrumbs.html
File metadata and controls
30 lines (25 loc) · 855 Bytes
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
{{- $url := . -}}
{{- $variant := "full" -}}
{{- /* Check if variant is passed as context (dict) or just the URL string */ -}}
{{- if reflect.IsMap . -}}
{{- $url = .url -}}
{{- $variant = .variant | default "full" -}}
{{- end -}}
{{- $urlObj := urls.Parse $url -}}
{{- $host := printf "%s://%s" $urlObj.Scheme $urlObj.Host -}}
{{- $pathname := $urlObj.Path -}}
{{- $breadcrumbs := slice -}}
{{- $segments := split $pathname "/" -}}
{{- $currentPath := "" -}}
{{- /* Default variant: Parse all segments */ -}}
{{- range $segments -}}
{{- if ne . "" -}}
{{- $currentPath = printf "%s%s/" $currentPath . -}}
{{- $fullUrl := printf "%s/%s" $host $currentPath -}}
{{- $breadcrumbs = $breadcrumbs | append $fullUrl -}}
{{- end -}}
{{- end -}}
{{- if gt (len $breadcrumbs) 0 -}}
{{- $breadcrumbs | jsonify }}
{{- else -}}
[]{{- end -}}