--- import { docResolver } from "./atproto"; import { type Blob, type LegacyBlob } from "@atcute/lexicons"; import { AppBskyFeedPost } from "@atcute/bluesky"; import { segmentize } from "@atcute/bluesky-richtext-segmenter"; import { type Author, understoodDid, type embed, type embedImages, type embedVideo, type embedExternal, type embedRecord, type embedRecordWithMedia, } from "./post-types"; import { images, video, external, record, recordWithMedia, } from "./post-embeds"; import BoxTlbr from "/assets/box-tlbr.png"; import Hr from "/assets/hr.png"; interface Props { post: AppBskyFeedPost.Main; author: Author; nested?: boolean; rkey: string; } const { post, author, nested = false, rkey } = Astro.props; // resolve the pds. bit hacky but should work const pds = await docResolver .resolve(understoodDid(author.did) ? author.did : "did:plc:failure") .then( (pds) => pds.service && pds.service.filter( (service) => service.type === "AtprotoPersonalDataServer", )[0].serviceEndpoint + "", ); // helper functions const cidSrc = (blob: Blob | LegacyBlob, did: `did:${string}:${string}`) => new URL( "/xrpc/com.atproto.sync.getBlob/?" + new URLSearchParams({ did: did, cid: "cid" in blob ? blob.cid : blob.ref.$link, }).toString(), pds, ).toString(); const embed: embed | null = await (async () => { if (!post.embed) return null; switch (post.embed.$type) { case "app.bsky.embed.images": return images(post.embed.images); case "app.bsky.embed.video": return video(post.embed.video, post.embed.alt, post.embed.captions); case "app.bsky.embed.external": return external(post.embed.external); case "app.bsky.embed.record": return await record(post.embed.record.uri, nested); case "app.bsky.embed.recordWithMedia": return recordWithMedia( post.embed.record.record.uri, post.embed.media, nested, ); } })(); ---
{author.avatar && } { author.displayName ? ( {author.displayName} ) : null } { !author.displayName ? ( Profile on aturi.to ) : null }

{ !post.facets ? post.text : segmentize(post.text.trim(), post.facets).map((x) => !x.features ? x.text : x.features.reduce( (acc, cur) => cur.$type === "app.bsky.richtext.facet#link" ? ( {acc} ) : cur.$type === "app.bsky.richtext.facet#mention" ? ( {acc} ) : ( {acc} ), x.text, )) }
{ embed && (
{(() => { const images = (img: embedImages) => img.images.map((image) => ( {image.alt} )); const video = (vid: embedVideo) => ( ); const external = (external: embedExternal) => ( {external.thumb && ( )} {external.title} {new URL(external.url).host} ); const record = (record: embedRecord) => { const uriFragments = record.uri.match( new RegExp( "at:\/\/(?did:(?:plc|web):[^\/]*)\/(?[^\/]*)\/(?.*)", ), ); let rkey: string = uriFragments?.groups?.rkey ?? ""; return record.record && record.author ? ( ) : (
Read More on aturi.to
); }; const recordWithMedia = (recordWMedia: embedRecordWithMedia) => { const quoted = recordWMedia.record && record(recordWMedia.record); const media = recordWMedia.media.$type === "app.bsky.embed.images" ? images(recordWMedia.media) : recordWMedia.media.$type === "app.bsky.embed.video" ? video(recordWMedia.media) : external(recordWMedia.media); return ( <> {media} {quoted} ); }; switch (embed.$type) { case "app.bsky.embed.images": return images(embed); case "app.bsky.embed.video": return video(embed); case "app.bsky.embed.external": return external(embed); case "app.bsky.embed.record": return record(embed); case "app.bsky.embed.recordWithMedia": return recordWithMedia(embed); } })()}
) }