get_logo.html 978 B

123456789101112131415161718192021
  1. {{/* Function to get logo image. */}}
  2. {{/* Inputs: constraint: max_height/fit (str); size (int) */}}
  3. {{/* Output: resource (obj) */}}
  4. {{/* Workaround fact Hugo does not support GetMatch in assets dir */}}
  5. {{/* Hugo doesn't support image ops on SVG: https://discourse.gohugo.io/t/ho-do-i-convert-a-generic-resource-to-image-resource/22570/4 */}}
  6. {{ $logo := resources.Get "media/logo.png" | default (resources.Get "media/logo.svg") }}
  7. {{ $logo_proc := $logo }}
  8. {{/* If the type of image can be resized by Hugo, resize it given a `.size` argument to the function. */}}
  9. {{ if resources.Get "media/logo.png" }}
  10. {{ if eq .constraint "max_height" }}
  11. {{/* Resize logo to fit specified max height. */}}
  12. {{ $logo_proc = ($logo.Resize (printf "x%s" (string .size))) }}
  13. {{ else }}
  14. {{/* Constrain logo to fit within specified dimensions. */}}
  15. {{ $logo_proc = ($logo.Fit (printf "%sx%s" (string .size) (string .size))) }}
  16. {{ end }}
  17. {{ end }}
  18. {{ return $logo_proc }}