Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GetFeaturedImage.html 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. {{/*
  2. GetFeaturedImage
  3. This partial gets the url for featured image for a given page.
  4. If a featured_image was set in the page's front matter, then that will be used.
  5. If not set, this will search page resources to find an image that contains the word
  6. "cover", and if found, returns the path to that resource.
  7. If no featured_image was set, and there's no "cover" image in page resources, then
  8. this partial returns an empty string (which evaluates to false).
  9. @return Permalink to featured image, or an empty string if not found.
  10. */}}
  11. {{/* Declare a new string variable, $linkToCover */}}
  12. {{ $linkToCover := "" }}
  13. {{/* Use the value from front matter if present */}}
  14. {{ if .Params.featured_image }}
  15. {{ $linkToCover = .Params.featured_image }}
  16. {{/* Find the first image with 'cover' in the name in this page bundle. */}}
  17. {{ else }}
  18. {{ $img := (.Resources.ByType "image").GetMatch "*cover*" }}
  19. {{ with $img }}
  20. {{ $linkToCover = .Permalink }}
  21. {{ end }}
  22. {{ end }}
  23. {{/* return either a permalink, or an empty string. Note that partials can only have a single
  24. return statement, so this needs to be at the end of the partial (and not in the if block) */}}
  25. {{ return $linkToCover }}