You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.7 KiB

4 years ago
  1. {{/*
  2. Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
  3. This file is part of After Dark.
  4. After Dark is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. After Dark is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */}}
  15. {{ $valid_processing_methods := (slice "resize" "fit" "fill") }}
  16. {{ $options := .options | default slice }}
  17. {{ $image_processing_method := default "fill" (index $options 0) }}
  18. {{ $image_processing_options := index $options 1 }}
  19. {{ if not (in $valid_processing_methods $image_processing_method) }}
  20. {{ errorf "Invalid thumbnail processing method: Must be one of 'fit', 'fill' or 'resize'." }}
  21. {{ else }}
  22. {{ $scratch := newScratch }}
  23. {{ with .node.Resources.GetMatch "*thumbnail*" }}
  24. {{ $meta_sameas := .Params.meta.sameas }}
  25. {{ $meta_license := .Params.meta.license }}
  26. {{ $meta_creator := .Params.meta.creator }}
  27. {{ $meta_description := .Params.meta.description }}
  28. {{ $meta_keywords := .Params.meta.keywords }}
  29. {{ $meta_contentlocation := .Params.meta.contentlocation }}
  30. {{ if (eq $image_processing_method "resize") }}
  31. {{ $scratch.Set "lodpi" (.Resize (default "400x300 q60 Gaussian" $image_processing_options)) }}
  32. {{ $scratch.Set "hidpi" (.Resize (printf "%dx%d q90 Gaussian" (mul ($scratch.Get "lodpi").Width 2) (mul ($scratch.Get "lodpi").Height 2))) }}
  33. {{ else if (eq $image_processing_method "fit") }}
  34. {{ $scratch.Set "lodpi" (.Fit (default "400x300" $image_processing_options)) }}
  35. {{ $scratch.Set "hidpi" (.Fit (printf "%dx%d" (mul ($scratch.Get "lodpi").Width 2) (mul ($scratch.Get "lodpi").Height 2))) }}
  36. {{ else }}
  37. {{ $scratch.Set "lodpi" (.Fill (default "400x300 Center" $image_processing_options)) }}
  38. {{ $scratch.Set "hidpi" (.Fill (printf "%dx%d Center" (mul ($scratch.Get "lodpi").Width 2) (mul ($scratch.Get "lodpi").Height 2))) }}
  39. {{ end }}
  40. <figure aria-hidden="true" itemscope itemtype="https://schema.org/ImageObject">
  41. <link itemprop="contentUrl" href="{{ .RelPermalink }}">
  42. <meta itemprop="encodingFormat" content="{{ .MediaType }}">
  43. <meta itemprop="name" content="{{ .Name | plainify }}">
  44. {{ with .Title }}
  45. <meta itemprop="headline" content="{{ . }}">
  46. {{ end }}
  47. {{ with $meta_creator }}
  48. <meta itemprop="creator" content="{{ . | plainify -}}">
  49. {{ end }}
  50. {{ if (urls.Parse $meta_sameas).Host }}
  51. <link itemprop="sameAs" href="{{ $meta_sameas }}">
  52. {{ end }}
  53. {{ if (urls.Parse $meta_license).Host }}
  54. <link itemprop="license" href="{{ $meta_license }}">
  55. {{ end }}
  56. {{ with $meta_keywords }}
  57. <meta itemprop="keywords" content="{{ delimit . ", " }}">
  58. {{ end }}
  59. {{ with $meta_contentlocation }}
  60. <meta itemprop="contentLocation" content="{{ . | plainify }}">
  61. {{ end }}
  62. {{ with $meta_description }}
  63. <meta itemprop="description" content="{{ . | plainify }}">
  64. {{ end }}
  65. <img
  66. itemprop="thumbnailUrl"
  67. alt="{{ with $meta_description }}{{ . }}{{ else }}{{ .Name | plainify }}{{ end }}"
  68. class="lazyload blur-up"
  69. src="{{ ($scratch.Get "lodpi").RelPermalink }}"
  70. data-src="{{ ($scratch.Get "hidpi").RelPermalink }}"
  71. >
  72. </figure>
  73. {{ end }}
  74. {{ end }}