Kaynağa Gözat

Fix invalid/empty image hrefs

Fixes #1413
Zed 2 ay önce
ebeveyn
işleme
bfcf75af7f
3 değiştirilmiş dosya ile 5 ekleme ve 0 silme
  1. 2 0
      src/utils.nim
  2. 1 0
      src/views/general.nim
  3. 2 0
      src/views/renderutils.nim

+ 2 - 0
src/utils.nim

@@ -40,12 +40,14 @@ proc getVidUrl*(link: string): string =
     &"/video/{sig}/{encodeUrl(link)}"
 
 proc getPicUrl*(link: string): string =
+  if link.len == 0: return
   if base64Media:
     &"/pic/enc/{encode(link, safe=true)}"
   else:
     &"/pic/{encodeUrl(link)}"
 
 proc getOrigPicUrl*(link: string): string =
+  if link.len == 0: return
   if base64Media:
     &"/pic/orig/enc/{encode(link, safe=true)}"
   else:

+ 1 - 0
src/views/general.nim

@@ -97,6 +97,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
       link(rel="preload", type="image/png", href=bannerUrl, `as`="image")
 
     for url in images:
+      if url.len == 0: continue
       let preloadUrl = if "400x400" in url: getPicUrl(url)
                        else: getSmallPic(url)
       link(rel="preload", type="image/png", href=preloadUrl, `as`="image")

+ 2 - 0
src/views/renderutils.nim

@@ -7,12 +7,14 @@ const smallWebp* = "?name=small&format=webp"
 const mediumWebp* = "?name=medium&format=webp"
 
 proc getSmallPic*(url: string): string =
+  if url.len == 0: return
   result = url
   if "?" notin url and not url.endsWith("placeholder.png"):
     result &= smallWebp
   result = getPicUrl(result)
 
 proc getMediumPic*(url: string): string =
+  if url.len == 0: return
   result = url
   if "?" notin url and not url.endsWith("placeholder.png"):
     result &= mediumWebp