diff options
author | Fredrik Jonsson <frjo@xdeb.org> | 2022-05-31 23:29:18 +0300 |
---|---|---|
committer | Fredrik Jonsson <frjo@xdeb.org> | 2022-05-31 23:29:18 +0300 |
commit | 6d9eeed6806b5b454132fcf70116196ea0e48fa8 (patch) | |
tree | 70ca90c2611e4ad8bf5e7a2768970a80246ce057 | |
parent | 196979ca6173973beade6fa4542b5efb038d4c10 (diff) |
Add svg shortcode.
-rw-r--r-- | layouts/shortcodes/svg.html | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/layouts/shortcodes/svg.html b/layouts/shortcodes/svg.html new file mode 100644 index 0000000..5dee9f9 --- /dev/null +++ b/layouts/shortcodes/svg.html @@ -0,0 +1,40 @@ +{{ $alt := .Get "alt" -}} +{{ $caption := .Get "caption" -}} +{{ $class := .Get "class" -}} +{{ $height := .Get "height" -}} +{{ $inline := .Get "inline" | default false -}} +{{ $link := .Get "link" -}} +{{ $src := .Get "src" -}} +{{ $width := .Get "width" -}} +{{ if and $src (fileExists (add "/assets" $src)) -}} + {{ $original := resources.Get $src -}} + {{ if $inline -}} + {{ $src = $original.Content -}} + {{ else -}} + {{ $src = $original.RelPermalink -}} + {{ end -}} +{{ else if and $src $inline (fileExists (add "/static" $src)) -}} + {{ $src = readFile (add "/static" $src) -}} +{{ end -}} +{{ if and $width $height -}} + {{ $width = int $width -}} + {{ $height = int $height -}} +{{ else if $width -}} + {{ $width = int $width -}} +{{ else if $height -}} + {{ $height = int $height -}} +{{ end -}} +{{ if $caption }}<figure class="image image--svg{{ with $class }} {{ . }}{{ end }}">{{ end -}} +{{ with $link }}<a class="image-link" href="{{ . }}">{{ end -}} +{{ if $inline -}} +<div class="image image--svg{{ with $class }} {{ . }}{{ end }}">{{ $src | safeHTML }}</div> +{{ else -}} +<img class="image image--svg{{ with $class }} {{ . }}{{ end }}" src="{{ $src }}"{{ with $alt }} alt="{{ . }}"{{ end }}{{ with $width }} width="{{ . }}"{{ end }}{{ with $height }} height="{{ . }}"{{ end }}> +{{ end -}} +{{- if $link }}</a>{{ end }} +{{ if $caption -}} +<figcaption> +{{ $caption | markdownify -}} +</figcaption> +</figure> +{{ end -}} |