about summary refs log tree commit diff
path: root/bskyembed
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-04-13 13:22:19 +0100
committerGitHub <noreply@github.com>2024-04-13 13:22:19 +0100
commit1a9eeb760ff0f9fcc8b7fd510ac3be7db889e95d (patch)
tree7e60f7831096e6a98f226ce264b3a58f422a9ab5 /bskyembed
parent4c95ec2ec403c355dbe118477e48e593b0512101 (diff)
downloadvoidsky-1a9eeb760ff0f9fcc8b7fd510ac3be7db889e95d.tar.zst
[Embeds] Add ref_url (#3533)
* get outer location and pass in to the iframe

* enable post.html in dev

* only add ref_url if starts with http

* Revert "enable post.html in dev"

This reverts commit 6f224c6e2c4a016f7ea17ff998c4b4e56b9a4f9b.

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'bskyembed')
-rw-r--r--bskyembed/snippet/embed.ts12
-rw-r--r--bskyembed/src/components/link.tsx6
2 files changed, 17 insertions, 1 deletions
diff --git a/bskyembed/snippet/embed.ts b/bskyembed/snippet/embed.ts
index f2b9b442e..380cda5fb 100644
--- a/bskyembed/snippet/embed.ts
+++ b/bskyembed/snippet/embed.ts
@@ -59,9 +59,19 @@ function scan(node = document) {
       continue
     }
 
+    const ref_url = location.origin + location.pathname
+
+    const searchParams = new URLSearchParams()
+    searchParams.set('id', id)
+    if (ref_url.startsWith('http')) {
+      searchParams.set('ref_url', encodeURIComponent(ref_url))
+    }
+
     const iframe = document.createElement('iframe')
     iframe.setAttribute('data-bluesky-id', id)
-    iframe.src = `${EMBED_URL}/embed/${aturi.slice('at://'.length)}?id=${id}`
+    iframe.src = `${EMBED_URL}/embed/${aturi.slice(
+      'at://'.length,
+    )}?${searchParams.toString()}`
     iframe.width = '100%'
     iframe.style.border = 'none'
     iframe.style.display = 'block'
diff --git a/bskyembed/src/components/link.tsx b/bskyembed/src/components/link.tsx
index db752542b..64c2c9a83 100644
--- a/bskyembed/src/components/link.tsx
+++ b/bskyembed/src/components/link.tsx
@@ -8,8 +8,14 @@ export function Link({
   href: string
   className?: string
 } & h.JSX.HTMLAttributes<HTMLAnchorElement>) {
+  const searchParam = new URLSearchParams(window.location.search)
+  const ref_url = searchParam.get('ref_url')
+
   const newSearchParam = new URLSearchParams()
   newSearchParam.set('ref_src', 'embed')
+  if (ref_url) {
+    newSearchParam.set('ref_url', ref_url)
+  }
 
   return (
     <a