fedimbed.bluesky: facet support
This commit is contained in:
		
							parent
							
								
									ce341409fb
								
							
						
					
					
						commit
						315341088c
					
				
					 1 changed files with 36 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -238,6 +238,42 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
    timestamp: post.record.createdAt,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  if (post.record.facets?.length > 0) {
 | 
			
		||||
    for (const facet of post.record.facets) {
 | 
			
		||||
      let replacement = mainEmbed.description.substring(facet.index.byteStart, facet.index.byteEnd);
 | 
			
		||||
      const original = replacement;
 | 
			
		||||
 | 
			
		||||
      for (const feature of facet.features) {
 | 
			
		||||
        switch (feature.$type) {
 | 
			
		||||
          case "app.bsky.richtext.facet#link": {
 | 
			
		||||
            if (replacement == feature.uri.replace(/^https?:\/\//, "")) {
 | 
			
		||||
              replacement = feature.uri;
 | 
			
		||||
            } else {
 | 
			
		||||
              replacement = `[${replacement}](${feature.uri})`;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
          case "app.bsky.richtext.facet#mention": {
 | 
			
		||||
            replacement = `[${replacement}](https://bsky.app/profile/${feature.did})`;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
          case "app.bsky.richtext.facet#tag": {
 | 
			
		||||
            replacement = `[${replacement}](https://bsky.app/hashtag/${feature.tag})`;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
          default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (replacement !== original)
 | 
			
		||||
        mainEmbed.description = `${mainEmbed.description.substring(
 | 
			
		||||
          0,
 | 
			
		||||
          facet.index.byteStart
 | 
			
		||||
        )}${replacement}${mainEmbed.description.substring(facet.index.byteEnd)}`;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (data.thread.parent) {
 | 
			
		||||
    const reply = data.thread.parent.post;
 | 
			
		||||
    mainEmbed.author = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue