Skip to content

Commit e07381d

Browse files
committed
Theme: Improve Params.redirect behavior and minor misc cleanup
1 parent 4221e27 commit e07381d

7 files changed

Lines changed: 151 additions & 68 deletions

File tree

themes/trigo/layouts/_partials/footer/menu_footer.html

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,40 @@
1919
<ul>
2020
{{- range site.Menus.footer -}}
2121

22+
{{- $url := .URL -}}
23+
{{- with .Page -}}
24+
{{- with .Params.redirect -}}
25+
{{- $url = . -}}
26+
{{- end -}}
27+
{{- end -}}
28+
{{- $is_external := and (hasPrefix $url "http") (not (hasPrefix $url site.BaseURL)) -}}
29+
2230
{{- $name := .Name -}}
2331
{{- with .Identifier -}}
2432
{{- with T . -}}
2533
{{- $name = . -}}
2634
{{- end -}}
2735
{{- end -}}
2836

29-
{{- $class := slice -}}
3037
{{- $aria := "" -}}
31-
{{- if or
32-
($first_section.IsMenuCurrent .Menu .)
33-
($first_section.HasMenuCurrent .Menu .)
34-
-}}
35-
{{- $class = $class | append "active" -}}
38+
{{- $class := slice -}}
39+
{{- if or ($first_section.IsMenuCurrent .Menu .) ($first_section.HasMenuCurrent .Menu .) -}}
3640
{{- $aria = "page" -}}
41+
{{- $class = $class | append "active" -}}
3742
{{- end -}}
3843
{{- with .Params.class -}}
3944
{{- $class = $class | append . -}}
4045
{{- end -}}
4146

42-
{{- $is_external := and (hasPrefix .URL "http") (not (hasPrefix .URL site.BaseURL)) -}}
43-
4447
{{- if or .Page $is_external -}}
4548
<li>
46-
<a href="{{ .URL }}"
47-
{{ with $class }}class="{{ delimit . " " }}"{{ end }}
49+
<a href="{{ $url }}"
4850
{{ with $aria }}aria-current="{{ . }}"{{ end }}
51+
{{ with $class }}class="{{ delimit . " " }}"{{ end }}
4952
{{ with .Params.style }}style="{{ . | safeCSS }}"{{ end }}
5053
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
5154
{{- $name -}}
55+
5256
{{- if $is_external -}}
5357
{{- partialCached "utils/icon.html" "external" "external" -}}
5458
{{- end -}}
@@ -58,13 +62,22 @@
5862
{{- if or .Page .Children -}}
5963
<ul>
6064
{{- range .Children -}}
61-
{{- $name := .Name -}}
62-
{{- $is_external := and (hasPrefix .URL "http") (not (hasPrefix .URL site.BaseURL)) -}}
65+
66+
{{- $child_url := .URL -}}
67+
{{- with .Page -}}
68+
{{- with .Params.redirect -}}
69+
{{- $child_url = . -}}
70+
{{- end -}}
71+
{{- end -}}
72+
{{- $is_external := and (hasPrefix $child_url "http") (not (hasPrefix $child_url site.BaseURL)) -}}
73+
6374
<li>
64-
<a href="{{ .URL }}"
75+
<a href="{{ $child_url }}"
76+
{{ with .Params.class }}class="{{ delimit . " " }}"{{ end }}
6577
{{ with .Params.style }}style="{{ . | safeCSS }}"{{ end }}
6678
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
67-
{{- $name -}}
79+
{{- .Name -}}
80+
6881
{{- if $is_external -}}
6982
{{- partialCached "utils/icon.html" "external" "external" -}}
7083
{{- end -}}
@@ -79,16 +92,28 @@
7992
(not .Params.no_listing)
8093
-}}
8194
{{- range .Pages.ByWeight -}}
95+
96+
{{- $page_url := .RelPermalink -}}
97+
{{- with .Page.Params.redirect -}}
98+
{{- $page_url = . -}}
99+
{{- end -}}
100+
{{- $is_external := and (hasPrefix $page_url "http") (not (hasPrefix $page_url site.BaseURL)) -}}
101+
82102
<li>
83-
<a href="{{ .RelPermalink }}"
103+
<a href="{{ $page_url }}"
84104
{{ with .Params.class }}class="{{ delimit . " " }}"{{ end }}
85-
{{ with .Params.style }}style="{{ . | safeCSS }}"{{ end }}>
105+
{{ with .Params.style }}style="{{ . | safeCSS }}"{{ end }}
106+
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
86107
{{- .LinkTitle -}}
108+
109+
{{- if $is_external -}}
110+
{{- partialCached "utils/icon.html" "external" "external" -}}
111+
{{- end -}}
87112
</a>
88113
</li>
89114
{{- end -}}
90115

91-
{{- else if eq .Section (index site.MainSections 0) }}
116+
{{- else if eq .Section (index site.MainSections 0) -}}
92117
{{- $taxonomy_map := partialCached "utils/taxonomy_map.html" . "taxonomy_map" -}}
93118
{{- range $key, $value := $taxonomy_map -}}
94119
{{- if hasSuffix $key "_data" -}}
@@ -106,10 +131,9 @@
106131

107132
</ul>
108133
{{- end -}}
109-
110134
</li>
111135
{{- end -}}
112-
{{- end -}}
113136

137+
{{- end -}}
114138
</ul>
115139
</nav>

themes/trigo/layouts/_partials/header/menu_main.html

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,47 @@
3030
<ul popover id="menu-list" class="menu-list">
3131
{{- range site.Menus.main -}}
3232

33+
{{- $url := .URL -}}
34+
{{- with .Page -}}
35+
{{- with .Params.redirect -}}
36+
{{- $url = . -}}
37+
{{- end -}}
38+
{{- end -}}
39+
{{- $is_external := and (hasPrefix $url "http") (not (hasPrefix $url site.BaseURL)) -}}
40+
3341
{{- $name := .Name -}}
3442
{{- with .Identifier -}}
3543
{{- with T . -}}
3644
{{- $name = . -}}
3745
{{- end -}}
3846
{{- end -}}
3947

40-
{{- $class := slice -}}
4148
{{- $aria := "" -}}
42-
{{- if or
43-
($first_section.IsMenuCurrent .Menu .)
44-
($first_section.HasMenuCurrent .Menu .)
45-
-}}
46-
{{- $class = $class | append "active" -}}
49+
{{- $class := slice -}}
50+
{{- if or ($first_section.IsMenuCurrent .Menu .) ($first_section.HasMenuCurrent .Menu .) -}}
4751
{{- $aria = "page" -}}
52+
{{- $class = $class | append "active" -}}
4853
{{- end -}}
4954
{{- with .Params.class -}}
5055
{{- $class = $class | append . -}}
5156
{{- end -}}
5257

53-
{{- $is_external := and (hasPrefix .URL "http") (not (hasPrefix .URL site.BaseURL)) -}}
54-
5558
{{- if or .Page $is_external -}}
5659
<li>
57-
<a href="{{ .URL }}"
58-
title="{{ $name }}"
59-
{{ with $class }}class="{{ delimit . " " }}"{{ end }}
60+
<a href="{{ $url }}"
6061
{{ with $aria }}aria-current="{{ . }}"{{ end }}
62+
{{ with $class }}class="{{ delimit . " " }}"{{ end }}
6163
{{ with .Params.style }}style="{{ . | safeCSS }}"{{ end }}
6264
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
6365
{{- $name -}}
66+
6467
{{- if $is_external -}}
6568
{{- partialCached "utils/icon.html" "external" "external" -}}
6669
{{- end -}}
6770
</a>
6871
</li>
6972
{{- end -}}
73+
7074
{{- end -}}
7175
</ul>
7276
</nav>

themes/trigo/layouts/_partials/main/card.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
{{- $key := "" -}}
1919
{{- with .File -}}{{- $key = .Path -}}{{- else -}}{{- $key = .RelPermalink -}}{{- end -}}
2020

21+
{{- $href := .RelPermalink -}}
22+
{{- with .Page.Params.redirect -}}
23+
{{- $href = . -}}
24+
{{- end -}}
25+
{{- $is_external := and (hasPrefix $href "http") (not (hasPrefix $href site.BaseURL)) -}}
26+
2127
<a class="card"
22-
href="{{ with .Params.redirect }}{{ . }}{{ else }}{{ .RelPermalink }}{{ end }}"
23-
title="{{ .Title }}">
28+
href="{{ $href }}"
29+
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
2430

2531
{{- with (partialCached "main/card_image.html" . $key) -}}
2632
{{- . -}}
@@ -41,6 +47,10 @@
4147
<h3 class="card-title">
4248
{{- .Title -}}
4349

50+
{{- if $is_external -}}
51+
{{- partialCached "utils/icon.html" "external" "external" -}}
52+
{{- end -}}
53+
4454
{{- if .Draft }}
4555
<sup><span>[{{- i18n "draft" | default "Draft" -}}]</span></sup>
4656
{{- end -}}

themes/trigo/layouts/_partials/main/pagination.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,28 @@
5454
{{- end -}}
5555

5656
{{- with $item -}}
57+
58+
{{- $href := .RelPermalink -}}
59+
{{- with .Page.Params.redirect -}}
60+
{{- $href = . -}}
61+
{{- end -}}
62+
{{- $is_external := and (hasPrefix $href "http") (not (hasPrefix $href site.BaseURL)) -}}
63+
5764
<a class="page-item {{ $direction }}"
58-
href="{{ .RelPermalink }}"
59-
title="{{ i18n (printf "%s_%s" $direction $type) | default (printf "%s %s" (title $direction) $type) }}">
65+
href="{{ $href }}"
66+
title="{{ i18n (printf "%s_%s" $direction $type) | default (printf "%s %s" (title $direction) $type) }}"
67+
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
6068

6169
{{- if eq $direction "next" -}}
6270
{{- partialCached "utils/icon.html" $icon $icon -}}
6371
{{- end -}}
64-
{{- .LinkTitle -}}
72+
73+
{{- .LinkTitle -}}
74+
75+
{{- if $is_external -}}
76+
{{- partialCached "utils/icon.html" "external" "external" -}}
77+
{{- end -}}
78+
6579
{{- if eq $direction "prev" -}}
6680
{{- partialCached "utils/icon.html" $icon $icon -}}
6781
{{- end -}}

themes/trigo/layouts/_partials/utils/debug_info.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
(slice "Layout" .Layout)
2525
(slice "Path" .Path)
2626
(slice "RelPermalink" .RelPermalink)
27+
(slice "Params.redirect" .Params.redirect)
2728
(slice "Slug" .Slug)
2829
(slice "Language" .Language.Name)
2930
(slice "Weight" .Weight)

themes/trigo/layouts/home.html

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,40 @@
4242
{{- with $buttons -}}
4343
<div class="buttons">
4444
{{- range . -}}
45-
{{- $href := .link -}}
46-
{{- $label := .label -}}
47-
48-
{{- if and $href (not (hasPrefix $href "http")) -}}
49-
{{- with (site.GetPage $href) -}}
50-
{{- $href = .RelPermalink -}}
51-
{{- if not $label -}}
52-
{{- $label = .LinkTitle -}}
45+
46+
{{- $button_link := .link -}}
47+
{{- $button_label := .label -}}
48+
49+
{{- with $button_link -}}
50+
{{- with site.GetPage . -}}
51+
{{- with .Params.redirect -}}
52+
{{- $button_link = . -}}
53+
{{- else -}}
54+
{{- $button_link = .RelPermalink -}}
55+
{{- end -}}
56+
{{- if not $button_label -}}
57+
{{- $button_label = .LinkTitle -}}
5358
{{- end -}}
5459
{{- end -}}
5560
{{- end -}}
5661

57-
{{- if not $label -}}
58-
{{- $label = i18n "explore" | default "Explore" -}}
62+
{{- $is_external := and (hasPrefix $button_link "http") (not (hasPrefix $button_link site.BaseURL)) -}}
63+
64+
{{- if not $button_label -}}
65+
{{- $button_label = i18n "explore" | default "Explore" -}}
5966
{{- end -}}
6067

61-
<a href="{{ $href }}"
62-
title="{{ trim $label " " }}"
68+
<a href="{{ $button_link }}"
6369
class="hero-button"
64-
{{- with .style -}}style="{{ . | safeCSS }}"{{- end -}}>
65-
{{ $label }}
70+
{{ with .style }}style="{{ . | safeCSS }}"{{ end }}
71+
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
72+
{{- $button_label -}}
73+
74+
{{- if $is_external -}}
75+
{{- partialCached "utils/icon.html" "external" "external" -}}
76+
{{- end -}}
6677
</a>
78+
6779
{{- end -}}
6880
</div>
6981
{{- end -}}
@@ -72,32 +84,50 @@
7284
{{- if $hero -}}
7385

7486
{{- $hero_link := $hero.link -}}
75-
{{- $hero_page := site.GetPage $hero_link -}}
76-
{{- $is_external := not $hero_page -}}
77-
{{- $hero_cover := . -}}
78-
79-
{{- if $hero_page -}}
80-
{{- $hero_link = $hero_page.RelPermalink -}}
81-
{{- $hero_cover = $hero_page -}}
82-
{{- end -}}
83-
8487
{{- $hero_title := $hero.title -}}
85-
{{- if and $hero_page (not $hero_title) -}}
86-
{{- $hero_title = $hero_page.LinkTitle -}}
88+
{{- $hero_cover := $hero.cover -}}
89+
90+
{{- with $hero_link -}}
91+
{{- with site.GetPage . -}}
92+
{{- with .Params.redirect -}}
93+
{{- $hero_link = . -}}
94+
{{- else -}}
95+
{{- $hero_link = .RelPermalink -}}
96+
{{- end -}}
97+
{{- if not $hero_title -}}
98+
{{- $hero_title = .LinkTitle -}}
99+
{{- end -}}
100+
{{- if not $hero_cover -}}
101+
{{- $hero_cover = . -}}
102+
{{- end -}}
103+
{{- end -}}
87104
{{- end -}}
88105

89-
<a class="hero-column"
90-
href="{{ $hero_link }}"
91-
{{ if $is_external }}rel="noopener noreferrer"{{ end }}>
106+
{{- $is_external := and (hasPrefix $hero_link "http") (not (hasPrefix $hero_link site.BaseURL)) -}}
107+
108+
{{- with $hero_link -}}
109+
<a class="hero-column"
110+
href="{{ . }}"
111+
{{ if $is_external }}target="_blank" rel="noopener noreferrer"{{ end }}>
112+
{{- end -}}
92113

114+
{{- with $hero_title -}}
93115
<h2 class="title"
94116
{{ with .Params.hero.class }}class="{{ . }}"{{ end }}
95117
{{ with .Params.hero.style }}style="{{ . | safeCSS }}"{{ end }}>
96-
{{- $hero_title -}}
118+
{{- . -}}
119+
120+
{{- if $is_external -}}
121+
{{- partialCached "utils/icon.html" "external" "external" -}}
122+
{{- end -}}
97123
</h2>
124+
{{- end -}}
125+
126+
{{- with $hero_cover -}}
127+
{{- partialCached "main/cover.html" . . -}}
128+
{{- end -}}
98129

99-
{{- partialCached "main/cover.html" $hero_cover $hero_cover -}}
100-
</a>
130+
{{- with $hero_link -}}</a>{{- end -}}
101131

102132
{{- end -}}
103133
</section>

themes/trigo/layouts/list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ <h2 style="color: crimson; z-index:2;">Weight: {{ .Weight }}</h2>
6767

6868
{{- $taxonomy_map := partialCached "utils/taxonomy_map.html" . "taxonomy_map" -}}
6969
{{- range $key, $value := $taxonomy_map -}}
70-
{{- if hasSuffix $key "_data" -}}
70+
{{- if and (hasSuffix $key "_data") (gt $value.count 0) -}}
7171
{{- $link_title := lower $value.link_title -}}
7272
{{- $title := i18n $link_title | default $link_title -}}
7373
<a href="{{ $value.rel_permalink }}"
7474
class="hero-button">
75-
{{ partialCached "utils/icon.html" $link_title $link_title }}
75+
{{- partialCached "utils/icon.html" $link_title $link_title -}}
7676
{{ title $title }} ({{ $value.count }})
7777
</a>
7878
{{- end -}}

0 commit comments

Comments
 (0)