fedimbed.bluesky: facet support

This commit is contained in:
Cynthia Foxwell 2024-11-11 10:22:54 -07:00
parent ce341409fb
commit 315341088c

View file

@ -238,6 +238,42 @@ async function bluesky(msg, url, spoiler = false) {
timestamp: post.record.createdAt, 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) { if (data.thread.parent) {
const reply = data.thread.parent.post; const reply = data.thread.parent.post;
mainEmbed.author = { mainEmbed.author = {