get-hero.html 885 B

123456789101112131415161718192021222324
  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. {{ $heroImage = .Page.Resources.GetMatch .Params.hero }}
  6. {{ end }}
  7. {{ .Scratch.Set "heroScratch" $heroImage }}
  8. {{/* if hero image is not provided, then use the default hero image */}}
  9. {{ if not $heroImage }}
  10. {{ $heroImage := resources.Get "images/default-hero.jpg"}}
  11. {{ .Scratch.Set "heroScratch" $heroImage }}
  12. {{ end }}
  13. {{ $heroImage := .Scratch.Get "heroScratch" }}
  14. {{/* resize hero image. don't resize if the image is an svg */}}
  15. {{ if and $heroImage (ne $heroImage.MediaType.SubType "svg") }}
  16. {{ $heroImage := $heroImage.Resize "148x" }}
  17. {{ end }}
  18. {{/* return the hero image */}}
  19. {{ return $heroImage.RelPermalink }}