Skip to content

Commit 1631d13

Browse files
committed
refactoring
1 parent f36b267 commit 1631d13

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

layouts/partials/related.html

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{{ $pageType := .pageType | default .index }}
2+
{{ $related := slice }}
23

34
{{ if eq $pageType "booking" }}
45
{{ $slug := .page.File.ContentBaseName }}
56
{{ $operators := where .page.Site.RegularPages "Type" "operator" }}
6-
{{ $related := where $operators "Params.booking" "intersect" (slice $slug) }}
7+
{{ $related = where $operators "Params.booking" "intersect" (slice $slug) }}
8+
{{ else }}
9+
{{ $related = where (.page.Site.RegularPages.RelatedIndices .page .index) ".Page.Type" $pageType }}
10+
{{ end }}
711

12+
{{ if gt (len $related) 0 }}
813
<h3 id="o-related__title-{{ .identifier }}">{{ .title }}</h3>
914
<ul
1015
class="o-related__list"
@@ -13,50 +18,27 @@ <h3 id="o-related__title-{{ .identifier }}">{{ .title }}</h3>
1318
{{ range $related }}
1419
<li class="o-related__item">
1520
{{ $text := .LinkTitle }}
21+
{{ if eq .Page.Type "news" }}
22+
{{ $text = print (partial "icon" "newspaper") $text }}
23+
{{ else if or (eq .Page.Type "operator") (eq .Page.Type "booking") }}
1624
{{ $text = print (partial "operator-logo" (dict "operator" .File.ContentBaseName)) $text }}
25+
{{ else if eq .Page.Type "country" }}
26+
{{ $text = print (partial "flag" (dict "country" .File.ContentBaseName)) $text }}
27+
{{ end }}
1728

1829
{{ partial "internal_link" (
1930
dict
2031
"Destination" .RelPermalink
2132
"Text" ($text | .Page.RenderString)
2233
)
2334
}}
24-
</li>
25-
{{ end }}
26-
</ul>
27-
{{ else }}
28-
{{ $related := where (.page.Site.RegularPages.RelatedIndices .page .index) ".Page.Type" $pageType }}
29-
{{ if gt (len $related) 0 }}
30-
<h3 id="o-related__title-{{ .identifier }}">{{ .title }}</h3>
31-
<ul
32-
class="o-related__list"
33-
aria-labelledby="o-related__title-{{ .identifier }}"
34-
>
35-
{{ range $related }}
36-
<li class="o-related__item">
37-
{{ $text := .LinkTitle }}
38-
{{ if eq .Page.Type "news" }}
39-
{{ $text = print (partial "icon" "newspaper") $text }}
40-
{{ else if or (eq .Page.Type "operator") (eq .Page.Type "booking") }}
41-
{{ $text = print (partial "operator-logo" (dict "operator" .File.ContentBaseName)) $text }}
42-
{{ else if eq .Page.Type "country" }}
43-
{{ $text = print (partial "flag" (dict "country" .File.ContentBaseName)) $text }}
44-
{{ end }}
45-
46-
{{ partial "internal_link" (
47-
dict
48-
"Destination" .RelPermalink
49-
"Text" ($text | .Page.RenderString)
50-
)
51-
}}
5235

53-
{{ if eq .Page.Type "news" }}
54-
<span class="o-related__date"
55-
>{{ .Date | time.Format ":date_long" }}</span
56-
>
57-
{{ end }}
58-
</li>
36+
{{ if eq .Page.Type "news" }}
37+
<span class="o-related__date"
38+
>{{ .Date | time.Format ":date_long" }}</span
39+
>
5940
{{ end }}
60-
</ul>
41+
</li>
6142
{{ end }}
43+
</ul>
6244
{{ end }}

0 commit comments

Comments
 (0)