mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 09:16:05 +02:00
feat: include alt text in image/attachment property federating out
closes #13124
This commit is contained in:
@@ -743,6 +743,28 @@ Mocks.notes.public = async (post) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
attachment = normalizeAttachment(attachment);
|
attachment = normalizeAttachment(attachment);
|
||||||
|
|
||||||
|
// Retrieve alt text from content (if found)
|
||||||
|
if (source?.content && source?.mediaType === 'text/markdown') {
|
||||||
|
const mdImageRegex = /!\[(.+?)\]\(([^\\)]+)\)/g;
|
||||||
|
const found = new Map();
|
||||||
|
let current = mdImageRegex.exec(source.content);
|
||||||
|
while (current !== null) {
|
||||||
|
const [, alt, src] = current;
|
||||||
|
found.set(src.replace('-resized', ''), alt);
|
||||||
|
current = mdImageRegex.exec(source.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
attachment = attachment.map((attachment) => {
|
||||||
|
if (found.has(attachment.url)) {
|
||||||
|
attachment.name = found.get(attachment.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachment;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'image' seems to be used as the preview image in lemmy/piefed, use the first one.
|
||||||
const image = attachment.filter(entry => entry.type === 'Image')?.shift();
|
const image = attachment.filter(entry => entry.type === 'Image')?.shift();
|
||||||
// let preview;
|
// let preview;
|
||||||
let summary = null;
|
let summary = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user