|
| 1 | +<script setup lang="ts"> |
| 2 | +interface Props { |
| 3 | + uri: string |
| 4 | + cid: string |
| 5 | +} |
| 6 | +
|
| 7 | +const props = defineProps<Props>() |
| 8 | +const embedContainer = ref<HTMLElement | null>(null) |
| 9 | +
|
| 10 | +// Extract the post URL from the AT URI |
| 11 | +// Format: at://did:plc:xxx/app.bsky.feed.post/postId |
| 12 | +const getPostUrl = () => { |
| 13 | + const parts = props.uri.split('/') |
| 14 | + const did = parts[2] |
| 15 | + const postId = parts[parts.length - 1] |
| 16 | + return `https://bsky.app/profile/${did}/post/${postId}` |
| 17 | +} |
| 18 | +
|
| 19 | +const postUrl = getPostUrl() |
| 20 | +
|
| 21 | +onMounted(() => { |
| 22 | + // Load the Bluesky embed script |
| 23 | + const scriptId = 'bluesky-embed-script' |
| 24 | +
|
| 25 | + const initializeEmbed = () => { |
| 26 | + // Wait a bit longer and check multiple times |
| 27 | + let attempts = 0 |
| 28 | + const maxAttempts = 10 |
| 29 | +
|
| 30 | + const checkAndScan = () => { |
| 31 | + attempts++ |
| 32 | +
|
| 33 | + if ((window as any).bluesky?.scan) { |
| 34 | + console.log('Bluesky scan function found, triggering...') |
| 35 | + ;(window as any).bluesky.scan() |
| 36 | + } else if (attempts < maxAttempts) { |
| 37 | + console.log(`Waiting for Bluesky script... attempt ${attempts}`) |
| 38 | + setTimeout(checkAndScan, 200) |
| 39 | + } else { |
| 40 | + console.error('Bluesky embed script did not load properly') |
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | + setTimeout(checkAndScan, 100) |
| 45 | + } |
| 46 | +
|
| 47 | + if (!document.getElementById(scriptId)) { |
| 48 | + const script = document.createElement('script') |
| 49 | + script.id = scriptId |
| 50 | + script.src = 'https://embed.bsky.app/static/embed.js' |
| 51 | + script.async = true |
| 52 | + script.charset = 'utf-8' |
| 53 | +
|
| 54 | + script.onload = () => { |
| 55 | + console.log('Bluesky embed script loaded') |
| 56 | + initializeEmbed() |
| 57 | + } |
| 58 | +
|
| 59 | + script.onerror = () => { |
| 60 | + console.error('Failed to load Bluesky embed script') |
| 61 | + } |
| 62 | +
|
| 63 | + document.head.appendChild(script) |
| 64 | + } else { |
| 65 | + initializeEmbed() |
| 66 | + } |
| 67 | +}) |
| 68 | +</script> |
| 69 | + |
| 70 | +<template> |
| 71 | + <ClientOnly> |
| 72 | + <div class="bluesky-embed-wrapper my-6 rounded-lg" ref="embedContainer"> |
| 73 | + <blockquote |
| 74 | + class="bluesky-embed" |
| 75 | + :data-bluesky-uri="uri" |
| 76 | + :data-bluesky-cid="cid" |
| 77 | + data-bluesky-embed-color-mode="dark" |
| 78 | + > |
| 79 | + <p lang="en"> |
| 80 | + Loading Bluesky post... |
| 81 | + <a :href="postUrl" target="_blank" rel="noopener noreferrer">View on Bluesky</a> |
| 82 | + </p> |
| 83 | + </blockquote> |
| 84 | + </div> |
| 85 | + </ClientOnly> |
| 86 | +</template> |
| 87 | + |
| 88 | +<style scoped> |
| 89 | +.bluesky-embed-wrapper :deep(iframe) { |
| 90 | + border-radius: 0.7rem !important; |
| 91 | +} |
| 92 | +</style> |
0 commit comments