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,
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,43 @@
|
||||||
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>";
|
||||||
|
|
||||||
const heading = {
|
const heading = {
|
||||||
"like-of": "👍 {x} Likes",
|
"like-of": "👍 {x} Likes",
|
||||||
"repost-of": "🔁 {x} Reposts",
|
"repost-of": "🔁 {x} Reposts",
|
||||||
"bookmark-of": "🔖 {x} Bookmarks",
|
"bookmark-of": "🔖 {x} Bookmarks",
|
||||||
"mention-of": "💬 {x} Mentions",
|
"mention-of": "💬 {x} Mentions",
|
||||||
"in-reply-to": "💬 {x} Replies",
|
"in-reply-to": "💬 {x} Replies",
|
||||||
};
|
};
|
||||||
|
|
||||||
["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]);
|
||||||
webMentionsSection.append(avatarBlock);
|
webMentionsSection.append(avatarBlock);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
["in-reply-to", "mention-of"].forEach((type) => {
|
["in-reply-to", "mention-of"].forEach((type) => {
|
||||||
const replies = mentions.filter((m) => m["wm-property"] === type);
|
const replies = mentions.filter((m) => m["wm-property"] === type);
|
||||||
|
|
||||||
if (replies.length) {
|
if (replies.length) {
|
||||||
// render on webmentions section
|
// render on webmentions section
|
||||||
const repliesWrapper = createRepliesBlock(replies, heading[type]);
|
const repliesWrapper = createRepliesBlock(replies, heading[type]);
|
||||||
webMentionsSection.append(repliesWrapper);
|
webMentionsSection.append(repliesWrapper);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRepliesBlock(replies, heading) {
|
function createRepliesBlock(replies, heading) {
|
||||||
|
|
Loading…
Reference in a new issue