Ver Fonte

Support external header images

Close #461 and #488
Alex Hogen há 7 anos atrás
pai
commit
fdfc961f34

+ 7 - 1
layouts/partials/header_image.html

@@ -1,6 +1,12 @@
 {{ if .Params.header.image }}
 <div class="article-header">
-  <img src="{{ "/img/" | relURL }}{{ .Params.header.image }}" class="article-banner" itemprop="image">
+  {{ $img_src := urls.Parse .Params.header.image }}
+  {{ if $img_src.Scheme }}
+    <img src="{{ .Params.header.image }}" class="article-banner" itemprop="image">
+  {{ else }}
+    <img src="{{ "/img/" | relURL }}{{ .Params.header.image }}" class="article-banner" itemprop="image">
+  {{ end }}
+
   {{ with .Params.header.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
 </div>
 {{end}}

+ 6 - 1
layouts/partials/post_li.html

@@ -6,7 +6,12 @@
   {{ $preview := $post.Params.header.preview | default true }}
   {{ if and $post.Params.header.image $preview }}
   <a href="{{ $post.Permalink }}">
-    <img src="{{ "/img/" | relURL }}{{ $post.Params.header.image }}" class="article-banner" itemprop="image">
+    {{ $img_src := urls.Parse $post.Params.header.image }}
+    {{ if $img_src.Scheme }}
+      <img src="{{ $post.Params.header.image }}" class="article-banner" itemprop="image">
+    {{ else }}
+      <img src="{{ "/img/" | relURL }}{{ $post.Params.header.image }}" class="article-banner" itemprop="image">
+    {{ end }}
   </a>
   {{end}}
   <h3 class="article-title" itemprop="headline">

+ 6 - 1
layouts/partials/publication_li_detailed.html

@@ -8,7 +8,12 @@
   {{ if .Scratch.Get "image" }}
   <div>
     <a href="{{ .Permalink }}">
-      <img src="{{ "/img/" | relURL }}{{ .Scratch.Get "image" }}" class="pub-banner" itemprop="image">
+      {{ $img_src := urls.Parse .Scratch.Get "image" }}
+      {{ if $img_src.Scheme }}
+        <img src="{{ .Scratch.Get "image" }}" class="article-banner" itemprop="image">
+      {{ else }}
+        <img src="{{ "/img/" | relURL }}{{ .Scratch.Get "image" }}" class="article-banner" itemprop="image">
+      {{ end }}      
     </a>
   </div>
   {{ end }}

+ 6 - 1
layouts/partials/talk_li_detailed.html

@@ -8,7 +8,12 @@
   {{ if .Scratch.Get "image" }}
   <div>
     <a href="{{ .Permalink }}">
-      <img src="{{ "/img/" | relURL }}{{ .Scratch.Get "image" }}" class="pub-banner" itemprop="image">
+      {{ $img_src := urls.Parse .Scratch.Get "image" }}
+      {{ if $img_src.Scheme }}
+        <img src="{{ .Scratch.Get "image" }}" class="article-banner" itemprop="image">
+      {{ else }}
+        <img src="{{ "/img/" | relURL }}{{ .Scratch.Get "image" }}" class="article-banner" itemprop="image">
+      {{ end }} 
     </a>
   </div>
   {{ end }}