refactor: add ignored author URLs to render params

This commit is contained in:
Ayo Ayco 2024-05-05 10:03:52 +02:00
parent 64e6b24bd1
commit 3a75fe2a7f
2 changed files with 41 additions and 29 deletions

View file

@ -78,7 +78,11 @@
getMentions, getMentions,
renderMentions, renderMentions,
} from "/assets/js/webmention-utils.mjs"; } from "/assets/js/webmention-utils.mjs";
const ignoreAuthorUrls = [
"https://social.ayco.io/@ayo",
"https://fosstodon.org/@ayo",
"https://m.webtoo.ls/@ayo",
];
const ignorePaths = [ const ignorePaths = [
"/", "/",
"/categories/", "/categories/",
@ -96,7 +100,11 @@
if (!ignorePaths.includes(url.pathname)) { if (!ignorePaths.includes(url.pathname)) {
const mentions = getMentions(url.toString()) const mentions = getMentions(url.toString())
.then((mentions) => { .then((mentions) => {
renderMentions(mentions, ".blog-post__web-mentions"); renderMentions(
mentions,
".blog-post__web-mentions",
ignoreAuthorUrls
);
}) })
.catch((err) => console.log("err", err)); .catch((err) => console.log("err", err));
} }

View file

@ -1,8 +1,13 @@
export function renderMentions(mentions, rootSelector) { export function renderMentions(mentions, rootSelector, ignoreAuthorUrls = []) {
const webMentionsSection = document.querySelector(rootSelector); 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 = webMentionsSection.innerHTML =
"<h2 id='webmentions'>From Across the Web</h2>"; "<h2 id='webmentions'>From Across the Web</h2>";
@ -15,9 +20,7 @@ export function renderMentions(mentions, rootSelector) {
}; };
["like-of", "repost-of", "bookmark-of"].forEach((type) => { ["like-of", "repost-of", "bookmark-of"].forEach((type) => {
const mentionsOfType = mentions const mentionsOfType = mentions.filter((m) => m["wm-property"] === type);
.filter((m) => m.author.name !== "Ayo Ayco")
.filter((m) => m["wm-property"] === type);
if (mentionsOfType.length) { if (mentionsOfType.length) {
const avatarBlock = createAvatarBlock(mentionsOfType, heading[type]); const avatarBlock = createAvatarBlock(mentionsOfType, heading[type]);
@ -35,6 +38,7 @@ export function renderMentions(mentions, rootSelector) {
} }
}); });
} }
}
function createRepliesBlock(replies, heading) { function createRepliesBlock(replies, heading) {
const repliesWrapper = document.createElement("div"); const repliesWrapper = document.createElement("div");