From 3a75fe2a7ff57a9da0a56ea08b3b68ac53c69bf5 Mon Sep 17 00:00:00 2001 From: Ayo Ayco Date: Sun, 5 May 2024 10:03:52 +0200 Subject: [PATCH] refactor: add ignored author URLs to render params --- _includes/head.html | 12 +++++-- assets/js/webmention-utils.mjs | 58 ++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 3b880e9..c805316 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -78,7 +78,11 @@ getMentions, renderMentions, } from "/assets/js/webmention-utils.mjs"; - + const ignoreAuthorUrls = [ + "https://social.ayco.io/@ayo", + "https://fosstodon.org/@ayo", + "https://m.webtoo.ls/@ayo", + ]; const ignorePaths = [ "/", "/categories/", @@ -96,7 +100,11 @@ if (!ignorePaths.includes(url.pathname)) { const mentions = getMentions(url.toString()) .then((mentions) => { - renderMentions(mentions, ".blog-post__web-mentions"); + renderMentions( + mentions, + ".blog-post__web-mentions", + ignoreAuthorUrls + ); }) .catch((err) => console.log("err", err)); } diff --git a/assets/js/webmention-utils.mjs b/assets/js/webmention-utils.mjs index 0e3cbb2..cd07a39 100644 --- a/assets/js/webmention-utils.mjs +++ b/assets/js/webmention-utils.mjs @@ -1,39 +1,43 @@ -export function renderMentions(mentions, rootSelector) { +export function renderMentions(mentions, rootSelector, ignoreAuthorUrls = []) { const webMentionsSection = document.querySelector(rootSelector); - mentions = mentions.filter((m) => m["wm-private"] !== true); - if (mentions.filter((m) => m.author.name !== "Ayo Ayco").length) + mentions = mentions.filter( + (m) => m["wm-private"] !== true && !ignoreAuthorUrls.includes(m.author.url) + ); + + console.log(mentions); + + if (mentions.length) { webMentionsSection.innerHTML = "

From Across the Web

"; - const heading = { - "like-of": "👍 {x} Likes", - "repost-of": "🔁 {x} Reposts", - "bookmark-of": "🔖 {x} Bookmarks", - "mention-of": "💬 {x} Mentions", - "in-reply-to": "💬 {x} Replies", - }; + const heading = { + "like-of": "👍 {x} Likes", + "repost-of": "🔁 {x} Reposts", + "bookmark-of": "🔖 {x} Bookmarks", + "mention-of": "💬 {x} Mentions", + "in-reply-to": "💬 {x} Replies", + }; - ["like-of", "repost-of", "bookmark-of"].forEach((type) => { - const mentionsOfType = mentions - .filter((m) => m.author.name !== "Ayo Ayco") - .filter((m) => m["wm-property"] === type); + ["like-of", "repost-of", "bookmark-of"].forEach((type) => { + const mentionsOfType = mentions.filter((m) => m["wm-property"] === type); - if (mentionsOfType.length) { - const avatarBlock = createAvatarBlock(mentionsOfType, heading[type]); - webMentionsSection.append(avatarBlock); - } - }); + if (mentionsOfType.length) { + const avatarBlock = createAvatarBlock(mentionsOfType, heading[type]); + webMentionsSection.append(avatarBlock); + } + }); - ["in-reply-to", "mention-of"].forEach((type) => { - const replies = mentions.filter((m) => m["wm-property"] === type); + ["in-reply-to", "mention-of"].forEach((type) => { + const replies = mentions.filter((m) => m["wm-property"] === type); - if (replies.length) { - // render on webmentions section - const repliesWrapper = createRepliesBlock(replies, heading[type]); - webMentionsSection.append(repliesWrapper); - } - }); + if (replies.length) { + // render on webmentions section + const repliesWrapper = createRepliesBlock(replies, heading[type]); + webMentionsSection.append(repliesWrapper); + } + }); + } } function createRepliesBlock(replies, heading) {