Skip to content

Commit

Permalink
fix(container): use bgColor as the second background to avoid not see…
Browse files Browse the repository at this point in the history
…ing text before successfully loading background images (#149)

The bgColor will be fallback to primary color of background resource image if not set
  • Loading branch information
razonyang authored Jun 4, 2024
1 parent fbdc0cc commit 5bc5096
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions layouts/partials/bootstrap/container.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@
{{- with $class }}{{ $classes = $classes | append . }}{{ end }}
{{- $style := slice }}
{{- if ne $bg "" }}
{{- $bgRes := false }}
{{- $classes = $classes | append "" }}
{{- with .Page.Resources.Get $bg }}
{{- $bgRes = . }}
{{- $bg = .RelPermalink }}
{{- else }}
{{- with resources.Get $bg }}
{{- $bgRes = . }}
{{- $bg = .RelPermalink }}
{{- end }}
{{- end }}
{{- with and (eq $bgColor "") $bgRes }}
{{- with index .Colors 0 }}
{{- $bgColor = . }}
{{- end }}
{{- end }}
{{- $style = $style | append
(printf "background-image: url(%s)" $bg)
(cond
(ne $bgColor "")
(printf "background: url(%s), %s" $bg $bgColor)
(printf "background-image: url(%s)" $bg))
"background-size: cover"
}}
{{- end }}
{{- with $bgColor }}
{{- else if ne $bgColor "" }}
{{- $style = $style | append (printf "background-color: %s" .) }}
{{- end }}
<div
class="{{ delimit $classes ` ` }}"
{{ with $style }}{{ delimit . `;` | printf `style="%s"` | safeHTMLAttr }}{{ end }}>
{{ with $style }}{{ delimit . `; ` | printf `style="%s"` | safeHTMLAttr }}{{ end }}>
{{ .Inner }}
</div>

0 comments on commit 5bc5096

Please sign in to comment.