Changeset 7c62efb in Klonkt for src/views/partials


Ignore:
Timestamp:
06/25/2026 09:10:27 PM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
fc2b68b
Parents:
8ad1784
Message:

feat(ap): add 'Follow via the fediverse' button to the profile header

A visitor can now follow a Klonkt profile from their own fediverse account:
the button prompts for their server and bounces them to
<their-server>/authorize_interaction?uri=<this actor>, which Mastodon (and,
via the previous commit, Klonkt) renders as a Follow. Hidden in compact mode;
one-time-guarded delegated handler so it survives htmx chrome re-swaps.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/partials/profile-header.ejs

    r8ad1784 r7c62efb  
    8888        </ul>
    8989      <% } %>
     90
     91      <button type="button" class="profile-fedi-btn" data-fedi-actor-slug="<%= site.slug %>">
     92        🐘 <%= t('fedi.profile_follow') %>
     93      </button>
    9094    </div>
    9195
    9296  </div>
    9397</aside>
     98<script>
     99(function () {
     100  if (window.__pcmsFediFollowWired) return;
     101  window.__pcmsFediFollowWired = true;
     102  document.addEventListener('click', function (e) {
     103    var b = e.target.closest && e.target.closest('.profile-fedi-btn');
     104    if (!b) return;
     105    var raw = window.prompt(<%- JSON.stringify(t('fedi.remote_prompt')) %>, '');
     106    if (!raw) return;
     107    // Strip a full @user@host handle (and any scheme/path) down to the server host.
     108    var server = raw.trim().replace(/^@?[^@\s]*@/, '').replace(/^https?:\/\//i, '').replace(/\/.*$/, '').trim();
     109    if (!server) return;
     110    var actor = location.origin + '/ap/users/' + encodeURIComponent(b.getAttribute('data-fedi-actor-slug') || '');
     111    location.href = 'https://' + server + '/authorize_interaction?uri=' + encodeURIComponent(actor);
     112  });
     113})();
     114</script>
    94115<% } %>
    95116
     
    250271.on-special .profile-links,
    251272.on-archive .profile-links { display: none; }
     273
     274/* Follow-via-fediverse button */
     275.profile-fedi-btn {
     276  margin-top: 0.65rem;
     277  display: inline-flex; align-items: center; gap: 0.4rem;
     278  padding: 0.4rem 0.85rem;
     279  border: 1px solid var(--rule);
     280  border-radius: 999px;
     281  background: var(--paper-2);
     282  color: var(--ink-soft);
     283  font: inherit; font-size: 0.85rem; font-weight: 600;
     284  cursor: pointer;
     285  transition: border-color 120ms, color 120ms, background 120ms;
     286}
     287.profile-fedi-btn:hover { border-color: var(--accent); color: var(--ink); }
     288.on-post .profile-fedi-btn,
     289.on-special .profile-fedi-btn,
     290.on-search .profile-fedi-btn,
     291.on-archive .profile-fedi-btn { display: none; }
    252292</style>
Note: See TracChangeset for help on using the changeset viewer.