this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

like & repost counts for webmentions

+16 -12
+16 -12
app/views/articles/show.html.erb
··· 49 49 <div id="webmentions_bbgm"> 50 50 <h3 id="webmentions">webmentions</h3> 51 51 52 - <ul id="wbm-mentions-list" style="margin-block-end:1.5rem;"></ul> 52 + <ul id="wbm-mentions-list" style="margin-block-end:1.5rem;">loading...</ul> 53 53 54 - <!-- 55 - <details> 56 - <summary>likes</summary> 57 - <ul id="wbm-likes-list"></ul> 58 - </details> 59 - --> 54 + <ul id="wbm-likes-rbs-count">loading...</ul> 55 + 60 56 <script> 61 57 async function wbmJson() { 62 58 const postUrl = window.location.href; 63 59 64 60 mentions = await fetch("https://webmention.io/api/mentions.jf2?target=" + postUrl).then(res => res.json()).then((res) => res.children); 61 + 62 + mentionsLikeCount = await fetch("https://webmention.io/api/count.json?target=" + postUrl).then(res => res.json()).then((res) => res.type.like); 63 + 64 + mentionsRbCount = await fetch("https://webmention.io/api/count.json?target=" + postUrl).then(res => res.json()).then((res) => res.type.repost); 65 65 66 66 document.getElementById("wbm-mentions-list").innerHTML = mentions.filter((wm) => ["in-reply-to", "mention-of"].includes(wm["wm-property"])).map((m) => ( 67 67 `<li> ··· 69 69 </li>` 70 70 )) 71 71 72 - // document.getElementById("wbm-likes-list").innerHTML = mentions.filter((wm) => ["like-of"].includes(wm["wm-property"])).map((m) => ( 73 - // ` 74 - // <a href=${m.url}>${m.author.name}</a> 75 - // ` 76 - // )) 72 + if (mentionsLikeCount || mentionsRbCount) { 73 + document.getElementById("wbm-likes-rbs-count").innerHTML = 74 + `<li> 75 + <span style="color: var(--main-color);">${mentionsLikeCount}</span> likes 76 + </li> 77 + <li> 78 + <span style="color: var(--main-color);">${mentionsRbCount}</span> reposts 79 + </li>` 80 + } 77 81 }; 78 82 79 83 wbmJson();