Skip to content

Commit

Permalink
[Embeds] Add ref_url (#3533)
Browse files Browse the repository at this point in the history
* 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 6f224c6.

---------

Co-authored-by: Dan Abramov <[email protected]>
  • Loading branch information
mozzius and gaearon authored Apr 13, 2024
1 parent 4c95ec2 commit 1a9eeb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bskyembed/snippet/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions bskyembed/src/components/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a9eeb7

Please sign in to comment.