Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Fix issue in Embed preview
Sebastian Martinez committed 2 years ago
commit 0621067804a9ccdd3e5d17c79a24de10e9904d79
parent b6ac9bd4a7e0cbab2858a18f8af8abdce86f3250
1 file changed +21 -33
modified src/components/Markdown.svelte
@@ -79,7 +79,8 @@
      }
    }

-
    // If the embed is a preview stored in-memory.
+
    // Iterate over all images, and replace the source with a canonicalized URL
+
    // pointing at the projects /raw endpoint.
    for (const i of container.querySelectorAll("img")) {
      const imagePath = i.getAttribute("src");

@@ -89,42 +90,29 @@
          return e.oid === imagePath;
        });
        if (embed) {
-
          const fileExtension = embed.name.split(".").pop();
-
          if (fileExtension) {
-
            i.setAttribute("src", embed.content);
-
          }
-
        }
-
      }
-
    }
-

-
    // Iterate over all images, and replace the source with a canonicalized URL
-
    // pointing at the projects /raw endpoint.
-
    if (rawPath) {
-
      for (const i of container.querySelectorAll("img")) {
-
        const imagePath = i.getAttribute("src");
-

-
        // If the image is an oid embed
-
        if (imagePath && isCommit(imagePath)) {
-
          const fileExtension = i.alt.split(".").pop();
-
          const url = new URL(rawPath);
-
          // If a user changes the alt text of an image,
-
          // the browser is still able to infer the mime type.
-
          if (fileExtension && fileExtension in mimes) {
-
            url.search = `?mime=${mimes[fileExtension]}`;
-
          }
-
          url.pathname = canonicalize(`blobs/${imagePath}`, url.pathname);
-
          i.setAttribute("src", url.toString());
+
          i.setAttribute("src", embed.content);
          continue;
        }

-
        // Make sure the source isn't a URL before trying to fetch it from the repo
-
        if (
-
          imagePath &&
-
          !isUrl(imagePath) &&
-
          !imagePath.startsWith(`${router.base}twemoji`)
-
        ) {
-
          i.setAttribute("src", `${rawPath}/${canonicalize(imagePath, path)}`);
+
        const fileExtension = i.alt.split(".").pop();
+
        const url = new URL(rawPath);
+
        // If a user changes the alt text of an image,
+
        // the browser is still able to infer the mime type.
+
        if (fileExtension && fileExtension in mimes) {
+
          url.search = `?mime=${mimes[fileExtension]}`;
        }
+
        url.pathname = canonicalize(`blobs/${imagePath}`, url.pathname);
+
        i.setAttribute("src", url.toString());
+
        continue;
+
      }
+

+
      // Make sure the source isn't a URL before trying to fetch it from the repo
+
      if (
+
        imagePath &&
+
        !isUrl(imagePath) &&
+
        !imagePath.startsWith(`${router.base}twemoji`)
+
      ) {
+
        i.setAttribute("src", `${rawPath}/${canonicalize(imagePath, path)}`);
      }
    }