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" ) ) {
108 import ( "bluesky-post-embed" ) ;
9+ import ( "bluesky-profile-card-embed" ) ;
1110 }
1211
1312 const links = el . findAll ( "a" ) . filter ( link => {
1413 const href = link . getAttribute ( "href" ) ?? "" ;
15- return BSKY_POST_RE . test ( href ) ;
14+ return BSKY_POST_RE . test ( href ) || BSKY_PROFILE_RE . test ( href ) ;
1615 } ) ;
1716
1817 if ( links . length === 0 ) return ;
1918
2019 for ( const link of links ) {
21- const atUri = bskyPostATUri ( link . getAttribute ( "href" ) ?? "" ) ;
22- if ( ! atUri ) continue ;
23-
24- this . attachToggle ( link , atUri ) ;
20+ const postUri = bskyPostATUri ( link . getAttribute ( "href" ) ?? "" ) ;
21+ if ( postUri ) {
22+ this . attachToggle ( link , postUri ) ;
23+ return ;
24+ }
25+ const actor = bskyProfileActor ( link . getAttribute ( "href" ) ?? "" ) ;
26+ if ( actor ) {
27+ this . attachToggle ( link , undefined , actor ) ;
28+ }
2529 }
2630 }
2731
28- private attachToggle ( link : HTMLElement , uri : string ) {
29- const embedId = `bsky-embed-${ uri . replace ( / [: \/ ] / g, "-" ) } ` ;
30-
32+ private attachToggle ( link : HTMLElement , uri ?: string , actor ?: string ) {
3133 const btn = document . createElement ( "button" ) ;
3234 btn . setAttribute ( "aria-label" , "Toggle post embed" ) ;
3335 btn . addClass ( "bsky-embed-toggle" ) ;
@@ -36,18 +38,32 @@ export class BlueskyPostProcessor extends Component {
3638 link . insertAdjacentElement ( "afterend" , btn ) ;
3739
3840 btn . addEventListener ( "click" , ( ) => {
41+ let embedId = "" ;
42+ if ( uri ) {
43+ embedId = `bsky-post-embed-${ uri . replace ( / [: \/ ] / g, "-" ) } ` ;
44+ } else if ( actor ) {
45+ embedId = `bsky-profile-${ actor . replace ( / [: \/ ] / g, "-" ) } ` ;
46+ } else {
47+ return ;
48+ }
3949 const existing = document . getElementById ( embedId ) ;
4050 if ( existing ) {
4151 existing . remove ( ) ;
4252 setIcon ( btn , "message-circle" ) ;
4353 return ;
4454 }
4555
46- const embedEl = document . createElement ( "bluesky-post" ) as HTMLElement ;
56+ let embedEl : HTMLElement ;
57+ if ( actor ) {
58+ embedEl = document . createElement ( "bluesky-profile-card" ) as HTMLElement ;
59+ embedEl . setAttribute ( "actor" , actor ) ;
60+ } else {
61+ embedEl = document . createElement ( "bluesky-post" ) as HTMLElement ;
62+ embedEl . setAttribute ( "src" , uri ! ) ;
63+ }
64+
4765 embedEl . id = embedId ;
48- embedEl . setAttribute ( "src" , uri ) ;
4966 embedEl . setAttribute ( "allow-unauthenticated" , "" ) ;
50- embedEl . addClass ( "bsky-post-embed-wrapper" ) ;
5167
5268 btn . insertAdjacentElement ( "afterend" , embedEl ) ;
5369 setIcon ( btn , "x" ) ;
0 commit comments