commit - 815464f9c5929d1d03d7189b5eb65ba0396edea6
commit + d11bc342aae0489afa874fef2e05e07a9912b36b
blob - 80e4818bf595fd01240d0e346c8f63801d530834
blob + 8bf7544ea842d8d60b4a9e152a64caeb31cae32f
--- layouts/_partials/element.html
+++ layouts/_partials/element.html
{{- $tag := default "div" .tag -}}
-{{- $attrs := "" -}}
-{{- with .attributes -}}
- {{- range $k, $v := . -}}
- {{- $attrs = printf `%s %s=%q` $attrs $k $v -}}
- {{- end -}}
-{{- end -}}
-{{- printf "<%s%s>%s</%s>" $tag $attrs (default "" .inner) $tag | safeHTML -}}
+{{- printf "<%s" $tag | safeHTML -}}
+{{- partial "attrs.html" (.attributes | default dict) -}}
+{{- printf ">" | safeHTML -}}
+
+{{- default "" .inner | safeHTML -}}
+
+{{- printf "</%s>" $tag | safeHTML -}}
blob - /dev/null
blob + 55bd2e2e2aa557f2565a390f5554c9a49079fff7 (mode 644)
--- /dev/null
+++ layouts/_partials/attrs.html
+{{- range $name, $value := . -}}
+ {{- if ne $value nil -}}
+ {{- if eq (printf "%T" $value) "bool" -}}
+ {{- if $value -}}
+ {{- printf " %s" $name | safeHTMLAttr -}}
+ {{- end -}}
+ {{- else -}}
+ {{- printf " %s=%q" $name $value | safeHTMLAttr -}}
+ {{- end -}}
+ {{- end -}}
+{{- end -}}
blob - 34b5427c48b0945acd1bd46598cbc1d6b67edf70
blob + 8e6c39548689ac4ab96b8ea70a4439ecbe306962
--- layouts/_partials/head/favicon.html
+++ layouts/_partials/head/favicon.html
-{{- range resources.Match "{,**/}favicon.*" }}
- {{- $mediaType := .MediaType.Type }}
- {{- if eq $mediaType "image/svg+xml" }}
- {{- with . | minify }}
- <link rel="icon" {{ printf "type=%q" $mediaType | safeHTMLAttr }} href="{{ .RelPermalink }}">
- {{- end }}
- {{- else if eq $mediaType "image/vnd.microsoft.icon" }}
- <link rel="icon" {{ printf "type=%q" $mediaType | safeHTMLAttr }} href="{{ .RelPermalink }}">
- {{- else if hasPrefix $mediaType "image/" }}
- <link rel="icon" {{ printf "type=%q" $mediaType | safeHTMLAttr }} sizes="{{ .Width }}x{{ .Height }}" href="{{ .RelPermalink }}">
- {{- end }}
-{{- end }}
+{{- range resources.Match "{,**/}favicon.*" -}}
+ {{- if reflect.IsImageResource . -}}
+ {{- $resource := . -}}
+
+ {{- if eq .MediaType.Type "image/svg+xml" -}}
+ {{- $resource = . | minify -}}
+ {{- end -}}
+
+ {{- $attributes := dict
+ "rel" "icon"
+ "type" .MediaType.Type
+ "href" $resource.RelPermalink
+ -}}
+
+ {{- if reflect.IsImageResourceProcessable . -}}
+ {{- $attributes = merge $attributes (dict
+ "sizes" (printf "%dx%d" .Width .Height)
+ ) -}}
+ {{- end -}}
+
+ <link{{ partial "attrs.html" $attributes }}>
+ {{- end -}}
+{{- end -}}
blob - 5676ce2443a0c996549fa63f508a44195ca86e2d
blob + d86a9de4d9c5c2249548045a7c4a57f69698bbd7
--- layouts/_shortcodes/a.html
+++ layouts/_shortcodes/a.html
"aria-current"
"aria-describedby"
-}}
+
{{- $attributes := dict -}}
-{{- range $allowed -}}
- {{- $value := $.Get . -}}
- {{- if $value -}}
- {{- $attributes = merge $attributes (dict . $value) -}}
- {{- end -}}
+
+{{- range $name, $value := .Params -}}
+ {{- if in $allowed $name -}}
+ {{- $attributes = merge $attributes (dict $name $value) -}}
+ {{- end -}}
{{- end -}}
-{{- partial "element.html" (dict "tag" "a" "inner" .Inner "attributes" $attributes) -}}
+{{- partial "element.html" (dict
+ "tag" "a"
+ "inner" .Inner
+ "attributes" $attributes
+) -}}
blob - ec3e685fcdb82495e0a3ec97487e1de039ee5b39
blob + dd3e8886fe002d9caec6cf88aef7d7a79f1ba9fa
--- layouts/_shortcodes/section.html
+++ layouts/_shortcodes/section.html
-{{- $allowed := slice
- "class"
- "id"
--}}
+{{- $allowed := slice "class" "id" -}}
{{- $attributes := dict -}}
-{{- range $allowed -}}
- {{- $value := $.Get . -}}
- {{- if $value -}}
- {{- $attributes = merge $attributes (dict . $value) -}}
- {{- end -}}
+
+{{- range $name, $value := .Params -}}
+ {{- if in $allowed $name -}}
+ {{- $attributes = merge $attributes (dict $name $value) -}}
+ {{- end -}}
{{- end -}}
-{{- partial "element.html" (dict "tag" "section" "inner" .Inner "attributes" $attributes) -}}
+{{- partial "element.html" (dict
+ "tag" "section"
+ "inner" .Inner
+ "attributes" $attributes
+) -}}
blob - 921cd60f9b3ab88d884e5546adfc2d1ee441e39d
blob + 3ba203f999fae7f8dffd8690bd5c2cbbabe9a00f
--- layouts/_shortcodes/source.html
+++ layouts/_shortcodes/source.html
-{{- $src := .Get "src" -}}
-{{- if not $src -}}
- {{- $src = .InnerDeindent | strings.TrimSpace -}}
-{{- end -}}
-
+{{- $src := .Get "src" | default (.InnerDeindent | strings.TrimSpace) -}}
{{- $type := .Get "type" -}}
+
{{- if not $type -}}
- {{- with or ($.Page.Resources.Get $src) (resources.Get $src) (resources.GetRemote $src) -}}
+ {{- with or
+ (.Page.Resources.Get $src)
+ (resources.Get $src)
+ (resources.GetRemote $src)
+ -}}
{{- $type = .MediaType.Type -}}
{{- end -}}
{{- end -}}
-{{- if $type -}}
- {{- with .Get "codecs" }}
- {{- $type = printf `%s; codecs=%s` $type . -}}
+
+{{- $codecs := .Get "codecs" -}}
+{{- if and $type $codecs -}}
+ {{- $type = printf "%s; codecs=%s" $type $codecs -}}
+{{- end -}}
+
+{{- $allowed := slice
+ "srcset"
+ "sizes"
+ "media"
+ "width"
+ "height"
+-}}
+
+{{- $attributes := dict "src" $src -}}
+
+{{- range $name, $value := .Params -}}
+ {{- if in $allowed $name -}}
+ {{- $attributes = merge $attributes (dict $name $value) -}}
{{- end -}}
{{- end -}}
-<source src="{{ $src }}"{{ with $type }} type="{{ . }}"{{ end }}
- {{- range $attr := slice "srcset" "sizes" "media" "width" "height" -}}
- {{- with $.Get $attr }} {{ printf "%s=%q" $attr . | safeHTMLAttr }}{{- end -}}
- {{- end }} >
+{{- with $type -}}
+ {{- $attributes = merge $attributes (dict "type" .) -}}
+{{- end -}}
+
+<source{{ partial "attrs.html" $attributes }}>
blob - 4949c7c556c67a6122cc1b2ebf32376916f6a787
blob + 88fa63e3feb9a9939d2cd375aa2361ce9fe57e08
--- layouts/_shortcodes/video.html
+++ layouts/_shortcodes/video.html
-<video
- {{- range $attr := slice "class" "poster" "loading" "height" "width" "src" "tabindex" "area-hidden" -}}
- {{- with $.Get $attr }} {{ printf "%s=%q" $attr . | safeHTMLAttr }}{{- end -}}
+{{- $allowed := slice
+ "class"
+ "poster"
+ "height"
+ "width"
+ "src"
+ "tabindex"
+ "aria-hidden"
+ "autoplay"
+ "loop"
+ "muted"
+ "playsinline"
+ "disablepictureinpicture"
+ "disableremoteplayback"
+ "controls"
+-}}
+
+{{- $attributes := dict
+ "autoplay" true
+ "loop" true
+ "muted" true
+ "playsinline" true
+ "disablepictureinpicture" true
+ "disableremoteplayback" true
+ "controls" false
+-}}
+
+{{- range $name, $value := .Params -}}
+ {{- if in $allowed $name -}}
+ {{- $attributes = merge $attributes (dict $name $value) -}}
{{- end -}}
- {{- range $attr := slice "autoplay" "loop" "muted" "playsinline" "disablepictureinpicture" "disableremoteplayback" -}}
- {{- if ne ($.Get $attr | default "true") "false" }} {{ $attr }}{{- end -}}
- {{- end -}}
- {{- if ne ($.Get "controls" | default "false") "false" }} controls{{- end -}}
->
+{{- end -}}
+
+<video{{ partial "attrs.html" $attributes }}>
{{ .Inner }}
</video>