diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 4884fb2..2784dc6 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -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 = {