diff --git a/layouts/shortcodes/audio.html b/layouts/shortcodes/audio.html index 4f6f863..9878ca6 100644 --- a/layouts/shortcodes/audio.html +++ b/layouts/shortcodes/audio.html @@ -1,6 +1,39 @@ - - -{{ with .Get "src" }}{{ end }} +{{ $caption := .Get "caption" -}} +{{ $class := .Get "class" -}} +{{ $preload := .Get "preload" | default "metadata" -}} +{{ $src := .Get "src" -}} + +{{ $resource := false -}} +{{ $static := false -}} +{{ $type := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} +{{ end -}} + +{{ if $resource -}} + {{ $src = $resource.RelPermalink -}} + {{ $type = $resource.MediaType }} +{{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + + + + -{{ with .Get "caption" }}{{ . }}{{ end }} +{{ with $caption }}{{ . | markdownify }}{{ end }} diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 372bd6c..9c2be30 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -8,38 +8,54 @@ {{ $size := .Get "size" -}} {{ $src := .Get "src" -}} {{ $srcset := .Get "srcset" -}} -{{ $srcsetw := (slice) }} {{ $title := .Get "title" -}} {{ $width := .Get "width" -}} + {{ $maxwidth := site.Params.imageMaxWidth -}} {{ $realwidth := 0 -}} {{ $realheight := 0 -}} -{{ if and $src (fileExists (path.Join "/assets" $src)) -}} - {{ $original := resources.Get $src -}} +{{ $resource := false -}} +{{ $srcsetw := (slice) }} +{{ $static := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ with (imageConfig (path.Join "/static" $src)) -}} + {{ $realwidth = .Width -}} + {{ $realheight = .Height -}} + {{ end -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} +{{ end -}} + +{{ if $resource -}} {{ if $size -}} - {{ $image := $original.Resize $size -}} + {{ $image := $resource.Resize $size -}} {{ $src = $image.RelPermalink -}} {{ $width = $image.Width -}} {{ $height = $image.Height -}} {{ else -}} - {{ $src = $original.RelPermalink -}} - {{ $realwidth = $original.Width -}} - {{ $realheight = $original.Height -}} + {{ $src = $resource.RelPermalink -}} + {{ $realwidth = $resource.Width -}} + {{ $realheight = $resource.Height -}} {{ end -}} {{ if $srcset -}} {{ range $set := split $srcset " " -}} - {{ $image := $original.Resize (printf "%sx" $set) -}} + {{ $image := $resource.Resize (printf "%sx" $set) -}} {{ $srcsetw = $srcsetw | append (printf "%s %sw" $image.RelPermalink $set) }} {{ end }} {{ $width = "" -}} {{ $height = "" -}} {{ end -}} -{{ else if and $src (fileExists (path.Join "/static" $src)) -}} - {{ with (imageConfig (path.Join "/static" $src)) -}} - {{ $realwidth = .Width -}} - {{ $realheight = .Height -}} - {{ end -}} {{ end -}} + {{ if and $width $height -}} {{ $width = int $width -}} {{ $height = int $height -}} @@ -62,6 +78,13 @@ {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} {{ $height = (math.Round $height) -}} {{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + {{ with $link }}{{ end -}} diff --git a/layouts/shortcodes/file.html b/layouts/shortcodes/file.html index 44402fa..c8d7e57 100644 --- a/layouts/shortcodes/file.html +++ b/layouts/shortcodes/file.html @@ -2,11 +2,35 @@ {{ $newtab := .Get "newtab" | default false -}} {{ $src := .Get "src" -}} {{ $text := .Get "text" -}} -{{ if and $src (fileExists (path.Join "/assets" $src)) -}} - {{ $original := resources.Get $src -}} - {{ $src = $original.RelPermalink -}} + +{{ $resource := false -}} +{{ $static := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} {{ end -}} + +{{ if $resource -}} + {{ $src = $resource.RelPermalink -}} +{{ end -}} + {{ if not $text -}} {{ $text = path.Base $src -}} {{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + {{ $text }} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html index 546d6f8..c972159 100644 --- a/layouts/shortcodes/img.html +++ b/layouts/shortcodes/img.html @@ -5,37 +5,53 @@ {{ $size := .Get "size" -}} {{ $src := .Get "src" -}} {{ $srcset := .Get "srcset" -}} -{{ $srcsetw := (slice) }} {{ $width := .Get "width" -}} + {{ $maxwidth := site.Params.imageMaxWidth -}} {{ $realwidth := 0 -}} {{ $realheight := 0 -}} -{{ if and $src (fileExists (path.Join "/assets" $src)) -}} - {{ $original := resources.Get $src -}} +{{ $resource := false -}} +{{ $srcsetw := (slice) }} +{{ $static := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ with (imageConfig (path.Join "/static" $src)) -}} + {{ $realwidth = .Width -}} + {{ $realheight = .Height -}} + {{ end -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} +{{ end -}} + +{{ if $resource -}} {{ if $size -}} - {{ $image := $original.Resize $size -}} + {{ $image := $resource.Resize $size -}} {{ $src = $image.RelPermalink -}} {{ $width = $image.Width -}} {{ $height = $image.Height -}} {{ else -}} - {{ $src = $original.RelPermalink -}} - {{ $realwidth = $original.Width -}} - {{ $realheight = $original.Height -}} + {{ $src = $resource.RelPermalink -}} + {{ $realwidth = $resource.Width -}} + {{ $realheight = $resource.Height -}} {{ end -}} {{ if $srcset -}} {{ range $set := split $srcset " " -}} - {{ $image := $original.Resize (printf "%sx" $set) -}} + {{ $image := $resource.Resize (printf "%sx" $set) -}} {{ $srcsetw = $srcsetw | append (printf "%s %sw" $image.RelPermalink $set) }} {{ end }} {{ $width = "" -}} {{ $height = "" -}} {{ end -}} -{{ else if and $src (fileExists (path.Join "/static" $src)) -}} - {{ with (imageConfig (path.Join "/static" $src)) -}} - {{ $realwidth = .Width -}} - {{ $realheight = .Height -}} - {{ end -}} {{ end -}} + {{ if and $width $height -}} {{ $width = int $width -}} {{ $height = int $height -}} @@ -58,6 +74,13 @@ {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} {{ $height = (math.Round $height) -}} {{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + {{ with $link }}{{ end -}} {{- if $link }}{{ end }} diff --git a/layouts/shortcodes/svg.html b/layouts/shortcodes/svg.html index a32c21d..c2e7f96 100644 --- a/layouts/shortcodes/svg.html +++ b/layouts/shortcodes/svg.html @@ -6,16 +6,34 @@ {{ $link := .Get "link" -}} {{ $src := .Get "src" -}} {{ $width := .Get "width" -}} -{{ if and $src (fileExists (path.Join "/assets" $src)) -}} - {{ $original := resources.Get $src -}} - {{ if $inline -}} - {{ $src = $original.Content -}} - {{ else -}} - {{ $src = $original.RelPermalink -}} + +{{ $resource := false -}} +{{ $static := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ $static = true -}} + {{ $src = relURL $src -}} + {{ if $inline }} + {{ $src = readFile (path.Join "/static" $src) -}} + {{ end -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} {{ end -}} -{{ else if and $src $inline (fileExists (path.Join "/static" $src)) -}} - {{ $src = readFile (path.Join "/static" $src) -}} {{ end -}} + +{{ if $resource -}} + {{ if $inline -}} + {{ $src = $resource.Content -}} + {{ else -}} + {{ $src = $resource.RelPermalink -}} + {{ end -}} +{{ end -}} + {{ if and $width $height -}} {{ $width = int $width -}} {{ $height = int $height -}} @@ -24,6 +42,13 @@ {{ else if $height -}} {{ $height = int $height -}} {{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + {{ if $caption }}{{ end -}} {{ with $link }}{{ end -}} {{ if $inline -}} diff --git a/layouts/shortcodes/video.html b/layouts/shortcodes/video.html index 9ae5982..b54083e 100644 --- a/layouts/shortcodes/video.html +++ b/layouts/shortcodes/video.html @@ -1,6 +1,65 @@ - - -{{ with .Get "src" }}{{ end }} +{{ $autoplay := .Get "autoplay" -}} +{{ $caption := .Get "caption" -}} +{{ $class := .Get "class" -}} +{{ $loop := .Get "loop" -}} +{{ $poster := .Get "poster" -}} +{{ $preload := .Get "preload" | default "metadata" -}} +{{ $src := .Get "src" -}} +{{ $width := .Get "width" -}} + +{{ $posterres := false -}} +{{ $resource := false -}} +{{ $static := false -}} +{{ $type := false -}} + +{{ if and $src (fileExists (path.Join "/static" $src)) -}} + {{ $static = true -}} + {{ $src = relURL $src -}} +{{ else if $src -}} + {{ $src = strings.TrimLeft "/" $src -}} + {{ with resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} + {{ with .Page.Resources.Get $src -}} + {{ $resource = . -}} + {{ end -}} +{{ end -}} + +{{ if $resource -}} + {{ $src = $resource.RelPermalink -}} + {{ $type = $resource.MediaType }} +{{ end -}} + +{{ if and $poster (fileExists (path.Join "/static" $poster)) -}} + {{ $poster = relURL $poster -}} +{{ else if $poster -}} + {{ $poster = strings.TrimLeft "/" $poster -}} + {{ with resources.Get $poster -}} + {{ $posterres = . -}} + {{ end -}} + {{ with .Page.Resources.Get $poster -}} + {{ $posterres = . -}} + {{ end -}} +{{ end -}} + +{{ if $posterres -}} + {{ if $width -}} + {{ $image := $posterres.Resize (printf "%sx" $width) -}} + {{ $poster = $image.RelPermalink -}} + {{ else -}} + {{ $poster = $posterres.RelPermalink -}} + {{ end -}} +{{ end -}} + +{{ if not $src -}} +{{ warnf "%s shortcode number %d in \"content/%s\" is missing the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ else if not (or $static $resource) -}} +{{ warnf "%s shortcode number %d in \"content/%s\" has an error in the \"src\" attribute." .Name .Ordinal .Page.File.Path -}} +{{ end -}} + + + + -{{ with .Get "caption" }}{{ . }}{{ end }} +{{ with $caption }}{{ . | markdownify }}{{ end }}