refactor: add ignored author URLs to render params
This commit is contained in:
parent
64e6b24bd1
commit
3a75fe2a7f
2 changed files with 41 additions and 29 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
"<h2 id='webmentions'>From Across the Web</h2>";
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue