Changeset 4424af7 in Klonkt for src/services


Ignore:
Timestamp:
07/16/2026 12:20:51 PM (8 weeks ago)
Author:
Robin <roboburr@…>
Branches:
main
Children:
df9da7d
Parents:
ae05747
git-author:
Robin <roboburr@…> (07/12/2026 10:41:10 PM)
git-committer:
Robin <roboburr@…> (07/16/2026 12:20:51 PM)
Message:

Fix: linkify #hashtags and bare URLs in post bodies for on-site display

The website showed raw '#tag' and URL text in post bodies; only the
federated (Mastodon) copy got links, via buildNote. Add a shared
linkifyBody() that reuses the exact same linkHashtags()/linkUrls() rules and
apply it in the post render pipeline, so the site and the federated copy
agree. Idempotent (splits out existing <a>), so editor links and autoembeds
are never double-wrapped; hashtags point at the site's own /tag/<slug>.
@mention display-linking is deferred (needs a per-render webfinger lookup).

This is the first step of the compose/display pipeline unification; buildNote
should later call linkifyBody too so there is a single content pipeline.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    rae05747 r4424af7  
    14221422  return parts.join('');
    14231423}
     1424// Linkify inline #hashtags and bare URLs in BODY html for on-site DISPLAY, using the
     1425// EXACT same rules as the federated copy (linkHashtags/linkUrls), so the website and the
     1426// Mastodon copy agree instead of the website showing raw text. Idempotent: existing
     1427// <a>…</a> (editor links, embeds, shortcode buttons) are split out and left untouched, so
     1428// nothing is double-wrapped. Pass base='' → root-relative /tag/<slug> links.
     1429export function linkifyBody(base, html) {
     1430  const withTags = String(html || '')
     1431    .split(/(<a\b[^>]*>[\s\S]*?<\/a>)/gi)
     1432    .map((seg) => (/^<a\b/i.test(seg) ? seg : linkHashtags(base, seg)))
     1433    .join('');
     1434  return linkUrls(withTags);
     1435}
     1436
    14241437// Extract the AP Hashtag tag objects from already-linked reply content.
    14251438function hashtagTags(base, content) {
     
    24212434  deliverWithRetry, enqueueDelivery, processDeliveryQueue, startDeliveryWorker,
    24222435  getReplyUris, markNotificationsSeen, countUnseenNotifications, hasPlayableAudio,
     2436  linkifyBody,
    24232437};
Note: See TracChangeset for help on using the changeset viewer.