get-hero.html 1.1 KB

1234567891011121314151617181920212223242526272829
  1. {{/* check if there is any hero image in the same folder as the markdown file */}}
  2. {{ $heroImage := .Page.Resources.GetMatch "hero.{jpg,png,svg}"}}
  3. {{/* if hero image is specified in the page front-matter, then use that */}}
  4. {{ if .Params.hero }}
  5. {{/* try to read from the page bundle */}}
  6. {{ $heroImage = .Resources.Get .Params.hero }}
  7. {{/* if the image does not exist in the page bundle,try looking in the assets folder */}}
  8. {{ if not $heroImage }}
  9. {{ $heroImage = resources.Get .Params.hero }}
  10. {{ end }}
  11. {{ end }}
  12. {{ .Scratch.Set "heroScratch" $heroImage }}
  13. {{/* if hero image is not provided, then use the default hero image */}}
  14. {{ if not $heroImage }}
  15. {{ $heroImage := resources.Get "images/default-hero.jpg"}}
  16. {{ .Scratch.Set "heroScratch" $heroImage }}
  17. {{ end }}
  18. {{ $heroImage := .Scratch.Get "heroScratch" }}
  19. {{/* resize hero image. don't resize if the image is an svg */}}
  20. {{ if and $heroImage (ne $heroImage.MediaType.SubType "svg") }}
  21. {{ $heroImage := $heroImage.Resize "148x" }}
  22. {{ end }}
  23. {{/* return the hero image */}}
  24. {{ return $heroImage.RelPermalink }}