Changeset 2923a95 in Klonkt


Ignore:
Timestamp:
06/25/2026 05:57:01 AM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
30271e6
Parents:
ca25f360
Message:

feat(fediverse): audio posts skip image attachment so Mastodon shows the player card

A media attachment and a link/player card are mutually exclusive on Mastodon, so
the cover image was winning over the player card. Audio posts now omit image
attachments (the cover still shows as the player card's og:image thumbnail), so
Mastodon renders the inline player. Non-audio posts keep their image attachments.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    rca25f360 r2923a95  
    116116    return ({ jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif' })[(e || '').toLowerCase()] || 'image/jpeg';
    117117  };
     118  const hadAudio = /\[\[(track|album|playlist):/i.test(post.content || '');
    118119  const urls = [];
    119   if (post.cover_image_url) urls.push(abs(post.cover_image_url));
     120  // Audio posts suppress image attachments so Mastodon renders the player CARD
     121  // (twitter:player) instead of the cover — on Mastodon a media attachment and a
     122  // link/player card are mutually exclusive, and the inline player is the point.
     123  if (post.cover_image_url && !hadAudio) urls.push(abs(post.cover_image_url));
    120124  let body = post.content || '';
    121   for (const m of body.matchAll(/<img\b[^>]*\bsrc="([^"]+)"[^>]*>/gi)) urls.push(abs(m[1]));
     125  if (!hadAudio) for (const m of body.matchAll(/<img\b[^>]*\bsrc="([^"]+)"[^>]*>/gi)) urls.push(abs(m[1]));
    122126  body = body.replace(/<img\b[^>]*>/gi, '');
    123127  // Audio shortcodes: do NOT federate the raw audio file — Klonkt deliberately
     
    132136    for (const m of body.matchAll(/\[\[album:([^\]]+)\]\]/g)) audioLabels.push(m[1].trim());
    133137  } catch { /* non-fatal */ }
    134   const hadAudio = /\[\[(track|album|playlist):/i.test(body);
    135138  body = body.replace(/\[\[(track|album|playlist):[^\]]+\]\]/gi, '');
    136139  if (hadAudio) {
Note: See TracChangeset for help on using the changeset viewer.