11import { Component , MarkdownPostProcessorContext , setIcon } from "obsidian" ;
2- import { BSKY_POST_RE , bskyPostATUri } from "./util" ;
2+ import { BSKY_POST_RE , BSKY_PROFILE_RE , bskyPostATUri , bskyProfileActor } from "./util" ;
33
4-
5- export class BlueskyPostProcessor extends Component {
4+ export class BskyEmbedProcessor extends Component {
65
76 async process ( el : HTMLElement , _ctx : MarkdownPostProcessorContext ) {
8-
97 if ( ! customElements . get ( "bluesky-post" ) ) {
10- import ( "bluesky-post-embed" ) ;
8+ await import ( "bluesky-post-embed" ) ;
9+ }
10+ if ( ! customElements . get ( "bluesky-profile-card" ) ) {
11+ await import ( "bluesky-profile-card-embed" ) ;
1112 }
1213
1314 const links = el . findAll ( "a" ) . filter ( link => {
1415 const href = link . getAttribute ( "href" ) ?? "" ;
15- return BSKY_POST_RE . test ( href ) ;
16+ return BSKY_POST_RE . test ( href ) || BSKY_PROFILE_RE . test ( href ) ;
1617 } ) ;
1718
1819 if ( links . length === 0 ) return ;
1920
2021 for ( const link of links ) {
21- const atUri = bskyPostATUri ( link . getAttribute ( "href" ) ?? "" ) ;
22- if ( ! atUri ) continue ;
23-
24- this . attachToggle ( link , atUri ) ;
22+ const postUri = bskyPostATUri ( link . getAttribute ( "href" ) ?? "" ) ;
23+ if ( postUri ) {
24+ this . attachToggle ( link , postUri ) ;
25+ return ;
26+ }
27+ const actor = bskyProfileActor ( link . getAttribute ( "href" ) ?? "" ) ;
28+ if ( actor ) {
29+ this . attachToggle ( link , undefined , actor ) ;
30+ }
2531 }
2632 }
2733
28- private attachToggle ( link : HTMLElement , uri : string ) {
29- const embedId = `bsky-embed-${ uri . replace ( / [: \/ ] / g, "-" ) } ` ;
30-
34+ private attachToggle ( link : HTMLElement , uri ?: string , actor ?: string ) {
3135 const btn = document . createElement ( "button" ) ;
3236 btn . setAttribute ( "aria-label" , "Toggle post embed" ) ;
3337 btn . addClass ( "bsky-embed-toggle" ) ;
@@ -36,18 +40,32 @@ export class BlueskyPostProcessor extends Component {
3640 link . insertAdjacentElement ( "afterend" , btn ) ;
3741
3842 btn . addEventListener ( "click" , ( ) => {
43+ let embedId = "" ;
44+ if ( uri ) {
45+ embedId = `bsky-post-embed-${ uri . replace ( / [: / ] / g, "-" ) } ` ;
46+ } else if ( actor ) {
47+ embedId = `bsky-profile-${ actor . replace ( / [: / ] / g, "-" ) } ` ;
48+ } else {
49+ return ;
50+ }
3951 const existing = document . getElementById ( embedId ) ;
4052 if ( existing ) {
4153 existing . remove ( ) ;
4254 setIcon ( btn , "message-circle" ) ;
4355 return ;
4456 }
4557
46- const embedEl = document . createElement ( "bluesky-post" ) as HTMLElement ;
58+ let embedEl : HTMLElement ;
59+ if ( actor ) {
60+ embedEl = document . createElement ( "bluesky-profile-card" ) ;
61+ embedEl . setAttribute ( "actor" , actor ) ;
62+ } else {
63+ embedEl = document . createElement ( "bluesky-post" ) ;
64+ embedEl . setAttribute ( "src" , uri ! ) ;
65+ }
66+
4767 embedEl . id = embedId ;
48- embedEl . setAttribute ( "src" , uri ) ;
4968 embedEl . setAttribute ( "allow-unauthenticated" , "" ) ;
50- embedEl . addClass ( "bsky-post-embed-wrapper" ) ;
5169
5270 btn . insertAdjacentElement ( "afterend" , embedEl ) ;
5371 setIcon ( btn , "x" ) ;
0 commit comments