diff --git a/weblog/B0. Template/js/fediverse.js.md b/weblog/B0. Template/js/fediverse.js.md index bce48e3..afbc1fd 100644 --- a/weblog/B0. Template/js/fediverse.js.md +++ b/weblog/B0. Template/js/fediverse.js.md @@ -119,16 +119,18 @@ class FediSocial extends HTMLElement { customElements.define('fedi-social', FediSocial) -function renderReplies(status, replies, replyContainer, template) { +function renderReplies(status, replies, replyContainer, template, sharingUrl) { const repliesToThis = replies.filter(d => d.in_reply_to_id == status.id); repliesToThis.forEach(reply => { const article = template.content.cloneNode(true); + const permalink = sharingUrl ? sharingUrl.replace("{uri}", reply.uri) : reply.url + article.querySelector('.avatar').src = reply.account.avatar article.querySelector('a.name').href = reply.account.url article.querySelector('.name').innerText = reply.account.display_name - article.querySelector('a.permalink').href = reply.url + article.querySelector('a.permalink').href = permalink article.querySelector('time.dt-published').datetime = reply.created_at article.querySelector('time.dt-published').innerText = luxon.DateTime.fromISO(reply.created_at).toRelative() @@ -149,7 +151,8 @@ function renderReplies(status, replies, replyContainer, template) { } - article.querySelector('a.source').href = reply.url + article.querySelector('a.source').href = permalink + article.querySelectorAll('.fedi-social a').forEach(a => a.href = permalink) article.querySelector('.application').innerText = reply.application.name article.querySelector('.replies-count').innerText = reply.replies_count article.querySelector('.favourites-count').innerText = reply.favourites_count @@ -158,7 +161,7 @@ function renderReplies(status, replies, replyContainer, template) { if(reply.replies_count > 0) { const section = document.createElement('section') section.classList.add('replies') - renderReplies(reply, replies, section, template) + renderReplies(reply, replies, section, template, sharingUrl) article.querySelector('article').appendChild(section) } @@ -166,7 +169,7 @@ function renderReplies(status, replies, replyContainer, template) { }) } -async function loadContext(status, replyContainer, template) { +async function loadContext(status, replyContainer, template, sharingUrl) { try{ const res = await fetch(`https://monrepos.casa/api/v1/statuses/${status.id}/context`, { headers: { @@ -180,7 +183,7 @@ async function loadContext(status, replyContainer, template) { h1.innerText = "Replies" replyContainer.appendChild(h1) - renderReplies(status, json.descendants, replyContainer, template) + renderReplies(status, json.descendants, replyContainer, template, sharingUrl) } } catch(ex){ @@ -222,7 +225,7 @@ function fediverse() { const replyContainer = document.getElementById('fedi-social-replies') const template = document.getElementById('fedi-social-reply') - if(replyContainer && template && status.replies_count > 0) loadContext(status, replyContainer, template) + if(replyContainer && template && status.replies_count > 0) loadContext(status, replyContainer, template, data.template) } } catch(ex){