From e96dcfb4433ff9087108d0a49a1af97edd1f11b4 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 3 Aug 2020 11:36:48 +0200
Subject: [PATCH] [web] Fixed image links in MR preview.

Fixes #3021. At least for images in page bundles.
---
 web/layouts/_default/_markup/render-image.html | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/web/layouts/_default/_markup/render-image.html b/web/layouts/_default/_markup/render-image.html
index 8192bc36bfa..36f625a12b0 100644
--- a/web/layouts/_default/_markup/render-image.html
+++ b/web/layouts/_default/_markup/render-image.html
@@ -1,8 +1,17 @@
+{{ $url := .Destination }}
+{{ if eq hugo.Environment "staging" }}
+  {{ $imageFile := index (split .Destination "#") 0 }}
+  {{ $imageResource := .Page.Resources.GetMatch ($imageFile) }}
+  {{ with $imageResource }}
+    {{ $url = .RelPermalink }}
+  {{ end }}
+{{ end }}
+
 {{ if .Title }}
   <figure>
-    <img class="m-auto" src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
+    <img class="m-auto" src="{{ $url | safeURL }}" alt="{{ .Text }}">
     <figcaption>{{ .Title | safeHTML | markdownify }}</figcaption>
   </figure>
 {{ else }}
-  <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
+  <img src="{{ $url | safeURL }}" alt="{{ .Text }}">
 {{ end }}
-- 
GitLab