commit d11bc342aae0489afa874fef2e05e07a9912b36b from: Anton Kasimov date: Thu Aug 20 15:52:32 2026 UTC Реализация вставки атрибутов commit - 815464f9c5929d1d03d7189b5eb65ba0396edea6 commit + d11bc342aae0489afa874fef2e05e07a9912b36b blob - 80e4818bf595fd01240d0e346c8f63801d530834 blob + 8bf7544ea842d8d60b4a9e152a64caeb31cae32f --- layouts/_partials/element.html +++ layouts/_partials/element.html @@ -1,9 +1,9 @@ {{- $tag := default "div" .tag -}} -{{- $attrs := "" -}} -{{- with .attributes -}} - {{- range $k, $v := . -}} - {{- $attrs = printf `%s %s=%q` $attrs $k $v -}} - {{- end -}} -{{- end -}} -{{- printf "<%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 "" $tag | safeHTML -}} blob - /dev/null blob + 55bd2e2e2aa557f2565a390f5554c9a49079fff7 (mode 644) --- /dev/null +++ layouts/_partials/attrs.html @@ -0,0 +1,11 @@ +{{- 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 @@ -1,12 +1,23 @@ -{{- range resources.Match "{,**/}favicon.*" }} - {{- $mediaType := .MediaType.Type }} - {{- if eq $mediaType "image/svg+xml" }} - {{- with . | minify }} - - {{- end }} - {{- else if eq $mediaType "image/vnd.microsoft.icon" }} - - {{- else if hasPrefix $mediaType "image/" }} - - {{- 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 -}} + + + {{- end -}} +{{- end -}} blob - 5676ce2443a0c996549fa63f508a44195ca86e2d blob + d86a9de4d9c5c2249548045a7c4a57f69698bbd7 --- layouts/_shortcodes/a.html +++ layouts/_shortcodes/a.html @@ -15,12 +15,17 @@ "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 @@ -1,13 +1,14 @@ -{{- $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 @@ -1,21 +1,39 @@ -{{- $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 -}} - +{{- with $type -}} + {{- $attributes = merge $attributes (dict "type" .) -}} +{{- end -}} + + blob - 4949c7c556c67a6122cc1b2ebf32376916f6a787 blob + 88fa63e3feb9a9939d2cd375aa2361ce9fe57e08 --- layouts/_shortcodes/video.html +++ layouts/_shortcodes/video.html @@ -1,11 +1,36 @@ -