fedimbed.bluesky: i may be stupid

This commit is contained in:
Cynthia Foxwell 2024-11-11 10:37:47 -07:00
parent 315341088c
commit e4bcdf6f8a

View file

@ -239,39 +239,45 @@ async function bluesky(msg, url, spoiler = false) {
};
if (post.record.facets?.length > 0) {
const splitString = [];
let start = 0;
for (const facet of post.record.facets) {
let replacement = mainEmbed.description.substring(facet.index.byteStart, facet.index.byteEnd);
const original = replacement;
splitString.push({text: mainEmbed.description.substring(start, facet.index.byteStart)});
for (const feature of facet.features) {
splitString.push({
text: mainEmbed.description.substring(facet.index.byteStart, facet.index.byteEnd),
features: facet.features,
});
start = facet.index.byteEnd;
}
splitString.push({text: mainEmbed.description.substring(start)});
for (const part of splitString) {
for (const feature of part.features) {
switch (feature.$type) {
case "app.bsky.richtext.facet#link": {
if (replacement == feature.uri.replace(/^https?:\/\//, "")) {
replacement = feature.uri;
if (part.text == feature.uri.replace(/^https?:\/\//, "")) {
part.text = feature.uri;
} else {
replacement = `[${replacement}](${feature.uri})`;
part.text = `[${part.text}](${feature.uri})`;
}
break;
}
case "app.bsky.richtext.facet#mention": {
replacement = `[${replacement}](https://bsky.app/profile/${feature.did})`;
part.text = `[${part.text}](https://bsky.app/profile/${feature.did})`;
break;
}
case "app.bsky.richtext.facet#tag": {
replacement = `[${replacement}](https://bsky.app/hashtag/${feature.tag})`;
part.text = `[${part.text}](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)}`;
}
mainEmbed.description = splitString.map((part) => part.text).join("");
}
if (data.thread.parent) {