-
-
Notifications
You must be signed in to change notification settings - Fork 433
feat: added embedded bluesky post for markdown files #1297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
whitep4nth3r
merged 3 commits into
npmx-dev:feat/atproto-blog-fe
from
Kai-ros:feat/atproto-blog-fe
Feb 10, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <script setup lang="ts"> | ||
| import { BLUESKY_EMBED_BASE_ROUTE } from '#shared/utils/constants' | ||
| import type { BlueskyOEmbedResponse } from '#shared/schemas/atproto' | ||
|
|
||
| const { url } = defineProps<{ | ||
| url: string | ||
| }>() | ||
|
|
||
| const embeddedId = String(Math.random()).slice(2) | ||
| const iframeHeight = ref(300) | ||
|
|
||
| // INFO: Strictly eager client-side fetch (server: false & lazy: true) | ||
| const { data: embedData, status } = useLazyAsyncData<BlueskyOEmbedResponse>( | ||
| `bluesky-embed-${embeddedId}`, | ||
| () => | ||
| $fetch('/api/atproto/bluesky-oembed', { | ||
| query: { url, colorMode: 'system' }, | ||
| }), | ||
| { | ||
| // INFO: Redundant with .client.vue but included for surety that SSR is not attempted | ||
| server: false, | ||
| immediate: true, | ||
| }, | ||
| ) | ||
|
|
||
| // INFO: Computed URL with Unique ID appended for postMessage handshake, must be stable per component instance | ||
| const embedUrl = computed<string | null>(() => { | ||
| if (!embedData.value?.embedUrl) return null | ||
| return `${embedData.value.embedUrl}&id=${embeddedId}` | ||
| }) | ||
|
|
||
| const isLoading = computed(() => status.value === 'pending') | ||
|
|
||
| // INFO: REQUIRED - listener must attach after mount b/c window.postMessage only exists in the browser and the random ID must match between hydration and mount | ||
| onMounted(() => { | ||
| window.addEventListener('message', onPostMessage) | ||
| }) | ||
|
|
||
| onUnmounted(() => { | ||
| window.removeEventListener('message', onPostMessage) | ||
| }) | ||
|
|
||
| function onPostMessage(event: MessageEvent) { | ||
| if (event.origin !== BLUESKY_EMBED_BASE_ROUTE) return | ||
| if (event.data?.id !== embeddedId) return | ||
| if (typeof event.data?.height === 'number') { | ||
| iframeHeight.value = event.data.height | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <article class="bluesky-embed-container"> | ||
| <!-- Loading state --> | ||
| <LoadingSpinner | ||
| v-if="isLoading" | ||
| :text="$t('blog.atproto.loading_bluesky_post')" | ||
| aria-label="Loading Bluesky post..." | ||
| class="loading-spinner" | ||
| /> | ||
|
|
||
| <!-- Success state --> | ||
| <div v-else-if="embedUrl" class="bluesky-embed-container"> | ||
| <iframe | ||
| :data-bluesky-id="embeddedId" | ||
| :src="embedUrl" | ||
| width="100%" | ||
| :height="iframeHeight" | ||
| frameborder="0" | ||
| scrolling="no" | ||
| /> | ||
| </div> | ||
|
|
||
| <!-- Fallback state --> | ||
| <a v-else :href="url" target="_blank" rel="noopener noreferrer"> | ||
| {{ $t('blog.atproto.view_on_bluesky') }} | ||
| </a> | ||
| </article> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .bluesky-embed-container { | ||
| /* INFO: Matches Bluesky's internal max-width */ | ||
| max-width: 37.5rem; | ||
| width: 100%; | ||
| margin: 1.5rem 0; | ||
| /* INFO: Necessary to remove the white 1px line at the bottom of the embed. Also sets border-radius */ | ||
| clip-path: inset(0 0 1px 0 round 0.75rem); | ||
| } | ||
|
|
||
| .bluesky-embed-container > .loading-spinner { | ||
| margin: 0 auto; | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import EmbeddableBlueskyPost from '~/components/EmbeddableBlueskyPost.client.vue' | ||
|
|
||
| /** | ||
| * INFO: .md files are transformed into Vue SFCs by unplugin-vue-markdown during the Vite transform pipeline | ||
| * That transformation happens before Nuxt's component auto-import scanning can inject the proper imports | ||
| * Global registration ensures the component is available in the Vue runtime regardless of how the SFC was generated | ||
| */ | ||
| export default defineNuxtPlugin(nuxtApp => { | ||
| nuxtApp.vueApp.component('EmbeddableBlueskyPost', EmbeddableBlueskyPost) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { parse } from 'valibot' | ||
| import { handleApiError } from '#server/utils/error-handler' | ||
| import { | ||
| CACHE_MAX_AGE_ONE_MINUTE, | ||
| BLUESKY_API, | ||
| BLUESKY_EMBED_BASE_ROUTE, | ||
| ERROR_BLUESKY_EMBED_FAILED, | ||
| BLUESKY_URL_EXTRACT_REGEX, | ||
| } from '#shared/utils/constants' | ||
| import { type BlueskyOEmbedResponse, BlueskyOEmbedRequestSchema } from '#shared/schemas/atproto' | ||
|
|
||
| export default defineCachedEventHandler( | ||
| async (event): Promise<BlueskyOEmbedResponse> => { | ||
| try { | ||
| const query = getQuery(event) | ||
| const { url, colorMode } = parse(BlueskyOEmbedRequestSchema, query) | ||
|
|
||
| /** | ||
| * INFO: Extract handle and post ID from https://bsky.app/profile/HANDLE/post/POST_ID | ||
| * Casting type here because the schema has already validated the URL format before this line runs. | ||
| * If the schema passes, this regex is mathematically guaranteed to match and contain both capture groups. | ||
| * Match returns ["profile/danielroe.dev/post/123", "danielroe.dev", "123"] — only want the two capture groups, the full match string is discarded. | ||
| */ | ||
| const [, handle, postId] = url.match(BLUESKY_URL_EXTRACT_REGEX)! as [string, string, string] | ||
|
|
||
| // INFO: Resolve handle to DID using Bluesky's public API | ||
| const { did } = await $fetch<{ did: string }>( | ||
| `${BLUESKY_API}com.atproto.identity.resolveHandle`, | ||
| { | ||
| query: { handle }, | ||
| }, | ||
| ) | ||
|
|
||
| // INFO: Construct the embed URL with the DID | ||
| const embedUrl = `${BLUESKY_EMBED_BASE_ROUTE}/embed/${did}/app.bsky.feed.post/${postId}?colorMode=${colorMode}` | ||
|
|
||
| return { | ||
| embedUrl, | ||
| did, | ||
| postId, | ||
| handle, | ||
| } | ||
| } catch (error) { | ||
| handleApiError(error, { | ||
| statusCode: 502, | ||
| message: ERROR_BLUESKY_EMBED_FAILED, | ||
| }) | ||
| } | ||
| }, | ||
| { | ||
| name: 'bluesky-oembed', | ||
| maxAge: CACHE_MAX_AGE_ONE_MINUTE, | ||
| getKey: event => { | ||
| const { url, colorMode } = getQuery(event) | ||
| return `oembed:${url}:${colorMode ?? 'system'}` | ||
| }, | ||
| }, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.