placeholder.html 1.6 KB

123456789101112131415161718192021222324252627282930
  1. {{- /*
  2. Usage: `placeholder args`
  3. args can be one of the following:
  4. title: Used in the SVG `title` tag, default "Placeholder"
  5. text: The text to show in the image - default: "width x height"
  6. class: default: "bd-placeholder-img"
  7. color: The text color (foreground) - default: "#dee2e6"
  8. background: The background color - default: "#868e96"
  9. width: default: 100%
  10. height: default: 180px
  11. */ -}}
  12. {{- $grays := $.Site.Data.grays -}}
  13. {{- $title := .Get "title" | default "Placeholder" -}}
  14. {{- $class := .Get "class" -}}
  15. {{- $color := .Get "color" | default (index $grays 2).hex -}}
  16. {{- $background := .Get "background" | default (index $grays 5).hex -}}
  17. {{- $width := .Get "width" | default "100%" -}}
  18. {{- $height := .Get "height" | default "180" -}}
  19. {{- $text := .Get "text" | default (printf "%sx%s" $width $height) -}}
  20. {{- $show_title := not (eq $title "false") -}}
  21. {{- $show_text := not (eq $text "false") -}}
  22. <svg class="bd-placeholder-img{{ with $class }} {{ . }}{{ end }}" width="{{ $width }}" height="{{ $height }}" xmlns="http://www.w3.org/2000/svg"{{ if (or $show_title $show_text) }} role="img" aria-label="{{ if $show_title }}{{ $title }}{{ if $show_text }}: {{ end }}{{ end }}{{ if ($show_text) }}{{ $text }}{{ end }}"{{ else }} aria-hidden="true"{{ end }} preserveAspectRatio="xMidYMid slice" focusable="false">
  23. {{- if $show_title -}}<title>{{ $title }}</title>{{- end -}}
  24. <rect width="100%" height="100%" fill="{{ $background }}"/>
  25. {{- if $show_text -}}<text x="50%" y="50%" fill="{{ $color }}" dy=".3em">{{ $text }}</text>{{- end -}}
  26. </svg>