Skip to content

Commit

Permalink
fix: remove invalid indentations and empty line break, so that the pa…
Browse files Browse the repository at this point in the history
…rtial can be used in nested shortcode (#33)

Co-authored-by: TetraTheta <37061801+TetraTheta@users.noreply.github.com>
  • Loading branch information
razonyang and TetraTheta committed Jan 8, 2024
1 parent 6b2461d commit 30f968b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
4 changes: 4 additions & 0 deletions layouts/partials/images/figure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<figure class="{{ .figureClass }} {{ .wrapperClass }}">
{{ partial "images/picture" (merge .ctx (dict "className" (printf "%s %s" .figureImgClass .className))) }}
<figcaption class="{{ .figureCaptionClass }}">{{ .caption }}</figcaption>
</figure>
15 changes: 10 additions & 5 deletions layouts/partials/images/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,16 @@
{{- $figureClass := default "figure" $siteParams.figure_class_name }}
{{- $figureCaptionClass := default "figure-caption" $siteParams.figure_caption_class_name }}
{{- $figureImgClass := default "figure-img" $siteParams.figure_image_class_name }}
<figure class="{{ $figureClass }} {{ $wrapperClass }}">
{{ partial "images/picture" (merge $ctx (dict "className" (printf "%s %s" $figureImgClass $className))) }}
<figcaption class="{{ $figureCaptionClass }}">{{ $caption }}</figcaption>
</figure>
{{- partial "images/figure" (dict
"figureClass" $figureClass
"wrapperClass" $wrapperClass
"figureImgClass" $figureImgClass
"className" $className
"figureCaptionClass" $figureCaptionClass
"caption" $caption
"ctx" $ctx
) }}
{{- else }}
{{ partial "images/picture" (merge $ctx (dict "wrapperClass" $wrapperClass)) }}
{{- partial "images/picture" (merge $ctx (dict "wrapperClass" $wrapperClass)) }}
{{- end }}
{{- end -}}
40 changes: 29 additions & 11 deletions layouts/partials/images/picture.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
{{- range .sources }}
<source srcset="{{ .srcset }}" type="{{ .type }}" />
{{- end }}
<img
class="{{ .className }}"
src="{{ .src }}"
alt="{{ .alt }}"
{{ if .lazyLoading }}loading="lazy"{{ end }}
{{ with .naturalHeight }}height="{{ . }}"{{ end }}
{{ with .naturalWidth }}width="{{ . }}"{{ end }}
{{ with .style }}{{ printf `style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}
{{ if and .original .originalSrc }}data-src="{{ .originalSrc }}"{{ end }}
{{ if and .original .originalWidth }}data-width="{{ .originalWidth }}"{{ end }}
{{ if and .original .originalHeight }}data-height="{{ .originalHeight }}"{{ end }} />
{{- $attrs := slice
(printf `class="%s"` .className)
(printf `src="%s"` .src)
(printf `alt="%s"` .alt)
}}
{{- if .lazyLoading }}
{{- $attrs = $attrs | append `loading="lazy"` }}
{{- end }}
{{- with .naturalHeight }}
{{- $attrs = $attrs | append (printf `height="%d"` .) }}
{{- end }}
{{- with .naturalWidth }}
{{- $attrs = $attrs | append (printf `width="%d"` .) }}
{{- end }}
{{- with .style }}
{{- $attrs = $attrs | append (printf `style="%s"` (delimit . `; `)) }}
{{- end }}
{{- if .original }}
{{- with .originalSrc }}
{{- $attrs = $attrs | append (printf `data-src="%s"` .) }}
{{- end }}
{{- with .originalWidth }}
{{- $attrs = $attrs | append (printf `data-width="%d"` .) }}
{{- end }}
{{- with .originalHeight }}
{{- $attrs = $attrs | append (printf `data-height="%d"` .) }}
{{- end }}
{{- end }}
<img {{ delimit $attrs " " | safeHTMLAttr }} />
</picture>

0 comments on commit 30f968b

Please sign in to comment.