Эх сурвалжийг харах

feat: allow SVG as Hero image

George Cushen 4 жил өмнө
parent
commit
0994df7177

+ 5 - 0
wowchemy/assets/scss/wowchemy/widgets/_hero.scss

@@ -28,6 +28,11 @@
   /* Uncomment to standout on complicated backgrounds. */
   /* Uncomment to standout on complicated backgrounds. */
 }
 }
 
 
+// Prevent `.home-section.light a` setting text to same color as button bg (the primary color)
+.wg-hero.light a.btn {
+  color: #fff;
+}
+
 .wg-hero.dark a:not(.wg-hero .btn) {
 .wg-hero.dark a:not(.wg-hero .btn) {
   color: #fff;
   color: #fff;
 }
 }

+ 20 - 12
wowchemy/layouts/partials/widgets/hero.html

@@ -64,21 +64,29 @@
       {{- $image = resources.Get (path.Join "media" $page.Params.hero_media) -}}
       {{- $image = resources.Get (path.Join "media" $page.Params.hero_media) -}}
     {{- end -}}
     {{- end -}}
     {{ if $image }}
     {{ if $image }}
-      {{ $legacy_img := $image.Resize "400x" }}
-      {{ $img_src := "" }}
-      {{ $img_src_set := slice }}
-      {{ $widths := slice 1200 800 400 }}
+      {{ $isSVG := eq $image.MediaType.SubType "svg" }}
+      {{ if $isSVG -}}
 
 
-      {{ range $widths }}
-        {{ $src_link := ($image.Resize (printf "%dx" .)).RelPermalink }}
-        {{ if eq $img_src "" }}
-          {{ $img_src = $src_link }}
+        <img src="{{ $image.RelPermalink }}" alt="{{ $page.Title }}">
+
+      {{- else }}
+
+        {{ $legacy_img := $image.Resize "400x" }}
+        {{ $img_src := "" }}
+        {{ $img_src_set := slice }}
+        {{ $widths := slice 1200 800 400 }}
+
+        {{ range $widths }}
+          {{ $src_link := ($image.Resize (printf "%dx" .)).RelPermalink }}
+          {{ if eq $img_src "" }}
+            {{ $img_src = $src_link }}
+          {{ end }}
+          {{ $img_src_set = $img_src_set | append (printf "%s %dw" $src_link .) }}
         {{ end }}
         {{ end }}
-        {{ $img_src_set = $img_src_set | append (printf "%s %dw" $src_link .) }}
-      {{ end }}
-      {{ $img_src_set = delimit $img_src_set "," }}
+        {{ $img_src_set = delimit $img_src_set "," }}
 
 
-      <img src="{{ $legacy_img.RelPermalink }}" srcset="{{ $img_src_set }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $page.Title }}">
+        <img src="{{ $legacy_img.RelPermalink }}" srcset="{{ $img_src_set }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $page.Title }}">
+      {{ end }}
     {{ end }}
     {{ end }}
   </div>
   </div>
 </div>
 </div>