Turn image URls into absolute references so they work consistently with page URLS with or without a trailing /

This commit is contained in:
mtail 2018-05-31 10:32:50 -07:00
parent 6da31e24ac
commit da42e92238
3 changed files with 16 additions and 1590 deletions

View File

@ -40,7 +40,7 @@ $ kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo-deta
The updated architecture of the application now looks as follows:
{{< image width="80%" ratio="65.16%"
link="bookinfo-details-v2.svg"
link="../img/bookinfo-details-v2.svg"
caption="The Bookinfo Application with details V2"
>}}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 123 KiB

View File

@ -31,6 +31,21 @@ parameter.
{{ $title := or (.Get "title") (.Get "caption") }}
{{ $alt := or (.Get "alt") (.Get "title") (.Get "caption") }}
{{/* Turn relative values for $link into absolute URLs */}}
{{ $prefix := slicestr $link 0 1 }}
{{ if (eq $prefix "/") }}
{{ .Scratch.Set "link" $link }}
{{ else }}
{{ $prefix := slicestr $link 0 3 }}
{{ if (eq $prefix "../") }}
{{ $link := slicestr $link 3 }}
{{ .Scratch.Set "link" (printf "/%s%s" .Page.Dir $link) }}
{{ else }}
{{ .Scratch.Set "link" (printf "/%s%s" .Page.Dir $link) }}
{{ end }}
{{ end }}
{{ $link := printf "%s%s" .Site.BaseURL (.Scratch.Get "link") }}
<figure style="width: {{ $width }}">
<div class="wrapper-with-intrinsic-ratio" style="padding-bottom: {{ $ratio }}">
<a class="not-for-endnotes" href="{{ $link }}">