Skip to content

Commit c377de6

Browse files
committed
examples: assorted tweaks
* remove trailing slash * use urls.JoinPath * reindent * use `imageConfig` so that we add dimensions automatically
1 parent 6ce0c62 commit c377de6

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

site/content/docs/5.3/examples/_index.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ aliases: "/examples/"
2121
{{ range $i, $example := $entry.examples -}}
2222
{{- $len := len $entry.examples -}}
2323
{{ if (eq $i 0) }}<div class="row">{{ end }}
24-
{{ if $entry.external }}
24+
{{ if $entry.external -}}
2525
<div class="col-md-6 col-lg-4 mb-3 d-flex gap-3">
2626
<svg class="bi fs-5 flex-shrink-0 mt-1"><use xlink:href="#box-seam"></use></svg>
2727
<div>
2828
<h3 class="h5 mb-1">
29-
<a class="d-block link-offset-1" href="{{ $.Site.Params.github_org }}{{ $example.url }}/" target="_blank" rel="noopener">
29+
<a class="d-block link-offset-1" href="{{ urls.JoinPath $.Site.Params.github_org $example.url }}" target="_blank" rel="noopener">
3030
{{ $example.name }}
3131
</a>
3232
</h3>
@@ -43,23 +43,30 @@ aliases: "/examples/"
4343
</p>
4444
</div>
4545
</div>
46-
{{ else }}
46+
{{ else -}}
4747
<div class="col-sm-6 col-md-3 mb-3">
48-
<a class="d-block link-offset-1" href="/docs/{{ $.Site.Params.docs_version }}/examples/{{ $example.name | urlize }}/"{{ if in $example.name "RTL" }} hreflang="ar"{{ end }}>
49-
<img class="img-thumbnail mb-3" srcset="/docs/{{ $.Site.Params.docs_version }}/assets/img/examples/{{ $example.name | urlize }}.png,
50-
/docs/{{ $.Site.Params.docs_version }}/assets/img/examples/{{ $example.name | urlize }}@2x.png 2x"
51-
src="/docs/{{ $.Site.Params.docs_version }}/assets/img/examples/{{ $example.name | urlize }}.png"
52-
alt=""
53-
width="480" height="300"
54-
loading="lazy">
48+
<a class="d-block link-offset-1" href="{{ urls.JoinPath "/docs" $.Site.Params.docs_version "/examples" ($example.name | urlize) "/"}}"{{ if in $example.name "RTL" }} hreflang="ar"{{ end }}>
49+
{{ $imageBasePath := urls.JoinPath "/docs" $.Site.Params.docs_version "assets/img/examples" -}}
50+
{{- $imgPath := urls.JoinPath $imageBasePath (printf "%s%s" ($example.name | urlize) ".png") -}}
51+
{{- $imgPath2x := urls.JoinPath $imageBasePath (printf "%s%s" ($example.name | urlize) "@2x.png") -}}
52+
{{- with (imageConfig (path.Join "/site/static" $imgPath)) -}}
53+
<img class="img-thumbnail mb-3"
54+
srcset="{{ $imgPath }},
55+
{{ $imgPath2x }} 2x"
56+
src="{{ $imgPath }}"
57+
alt=""
58+
width="{{ .Width }}"
59+
height="{{ .Height }}"
60+
loading="lazy">
61+
{{- end }}
5562
<h3 class="h5 mb-1">
5663
{{ $example.name }}
5764
</h3>
5865
</a>
5966
<p class="text-body-secondary">{{ $example.description }}</p>
6067
</div>
61-
{{ end }}
62-
{{ if (eq (add $i 1) $len) }}</div>{{ end }}
68+
{{- end }}
69+
{{ if (eq (add $i 1) $len) }}</div>{{ end -}}
6370
{{ end -}}
6471
</div>
6572
{{ end -}}

0 commit comments

Comments
 (0)