Skip to content

Commit ab1a765

Browse files
authored
examples: assorted tweaks (#39772)
* remove trailing slash * use urls.JoinPath * reindent * use `imageConfig` so that we add dimensions automatically
1 parent 13f40f1 commit ab1a765

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Diff for: site/content/docs/5.3/examples/_index.md

+18-12
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,29 @@ 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 }}, {{ $imgPath2x }} 2x"
55+
src="{{ $imgPath }}"
56+
alt=""
57+
width="{{ .Width }}"
58+
height="{{ .Height }}"
59+
loading="lazy">
60+
{{- end }}
5561
<h3 class="h5 mb-1">
5662
{{ $example.name }}
5763
</h3>
5864
</a>
5965
<p class="text-body-secondary">{{ $example.description }}</p>
6066
</div>
61-
{{ end }}
62-
{{ if (eq (add $i 1) $len) }}</div>{{ end }}
67+
{{- end }}
68+
{{ if (eq (add $i 1) $len) }}</div>{{ end -}}
6369
{{ end -}}
6470
</div>
6571
{{ end -}}

0 commit comments

Comments
 (0)