feat: initial display replies from webmention.io
This commit is contained in:
parent
5bdebce4e6
commit
ae9ce08544
3 changed files with 99 additions and 38 deletions
|
@ -74,49 +74,78 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const url = document.URL.replace(
|
const ignore = ["/", "/categories/"];
|
||||||
"http://localhost:4000",
|
const url = new URL(
|
||||||
"https://ayos.blog"
|
document.URL.replace("http://localhost:4000", "https://ayos.blog")
|
||||||
);
|
);
|
||||||
console.log("url: ", url);
|
if (!ignore.includes(url.pathname)) {
|
||||||
const mentions = getMentions(url)
|
console.log("url: ", url);
|
||||||
.then((mentions) => {
|
const mentions = getMentions(url.toString())
|
||||||
const likes = mentions.filter((m) => m["wm-property"] === "like-of");
|
.then((mentions) => {
|
||||||
console.log("likes", likes);
|
const likes = mentions.filter((m) => m["wm-property"] === "like-of");
|
||||||
if (likes.length)
|
console.log("likes", likes);
|
||||||
document.getElementById(
|
if (likes.length)
|
||||||
"page-likes"
|
document.getElementById(
|
||||||
).innerHTML = `${likes.length} likes`;
|
"page-likes"
|
||||||
|
).innerHTML = `${likes.length} likes`;
|
||||||
|
|
||||||
const replies = mentions.filter(
|
const replies = mentions.filter(
|
||||||
(m) => m["wm-property"] === "in-reply-to"
|
(m) => m["wm-property"] === "in-reply-to"
|
||||||
);
|
);
|
||||||
console.log("replies", replies);
|
console.log("replies", replies);
|
||||||
if (replies.length)
|
if (replies.length) {
|
||||||
document.getElementById(
|
// render to post header meta
|
||||||
"page-replies"
|
document.getElementById(
|
||||||
).innerHTML = `${replies.length} replies`;
|
"page-replies"
|
||||||
|
).innerHTML = `${replies.length} replies`;
|
||||||
|
|
||||||
const reposts = mentions.filter(
|
// render to replies section
|
||||||
(m) => m["wm-property"] === "repost-of"
|
const repliesTable = document.createElement("table");
|
||||||
);
|
replies.forEach((reply) => {
|
||||||
console.log("reposts", reposts);
|
const row = document.createElement("tr");
|
||||||
if (reposts.length)
|
const cell = document.createElement("td");
|
||||||
document.getElementById(
|
row.append(cell);
|
||||||
"page-reposts"
|
const author = document.createElement("p");
|
||||||
).innerHTML = `${reposts.length} reposts`;
|
author.className = "author-wrapper";
|
||||||
|
author.innerHTML = `<img class="reply-photo" src="${
|
||||||
|
reply.author.photo
|
||||||
|
}" /> <span class="reply-name">${
|
||||||
|
reply.author.name
|
||||||
|
}</span><a href="${reply.url}" class="reply-date">${new Date(
|
||||||
|
reply.published
|
||||||
|
).toLocaleDateString()}</a><div class="clear-both"></div>`;
|
||||||
|
const replyBlock = document.createElement("quote");
|
||||||
|
replyBlock.innerHTML = reply.content.html;
|
||||||
|
replyBlock.insertBefore(author, replyBlock.firstChild);
|
||||||
|
cell.appendChild(replyBlock);
|
||||||
|
repliesTable.append(row);
|
||||||
|
});
|
||||||
|
document.querySelector("section#replies").append(repliesTable);
|
||||||
|
}
|
||||||
|
|
||||||
const others = mentions.filter(
|
const reposts = mentions.filter(
|
||||||
(m) =>
|
(m) => m["wm-property"] === "repost-of"
|
||||||
m["wm-property"] !== "like-of" &&
|
);
|
||||||
m["wm-property"] !== "in-reply-to" &&
|
console.log("reposts", reposts);
|
||||||
m["wm-property"] !== "repost-of"
|
if (reposts.length)
|
||||||
);
|
document.getElementById(
|
||||||
console.log("others", others);
|
"page-reposts"
|
||||||
|
).innerHTML = `${reposts.length} reposts`;
|
||||||
|
|
||||||
// console.log("mentions", mentions);
|
const others = mentions.filter(
|
||||||
})
|
(m) =>
|
||||||
.catch((err) => console.log("err", err));
|
m["wm-property"] !== "like-of" &&
|
||||||
|
m["wm-property"] !== "in-reply-to" &&
|
||||||
|
m["wm-property"] !== "repost-of"
|
||||||
|
);
|
||||||
|
console.log("others", others);
|
||||||
|
|
||||||
|
// console.log("mentions", mentions);
|
||||||
|
})
|
||||||
|
.catch((err) => console.log("err", err));
|
||||||
|
} else {
|
||||||
|
console.log("ignoring url: ", url);
|
||||||
|
}
|
||||||
|
|
||||||
async function getMentions(url) {
|
async function getMentions(url) {
|
||||||
let mentions = [];
|
let mentions = [];
|
||||||
|
|
30
_includes/replies-section.html
Normal file
30
_includes/replies-section.html
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<section id="replies"></section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
quote {
|
||||||
|
display: block;
|
||||||
|
margin: 1em 0;
|
||||||
|
padding: 1em;
|
||||||
|
border-left: 3px solid #ccc;
|
||||||
|
|
||||||
|
.author-wrapper {
|
||||||
|
display: block;
|
||||||
|
.reply-photo {
|
||||||
|
width: 2em;
|
||||||
|
height: 2em;
|
||||||
|
border-radius: 50%;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply-name,
|
||||||
|
.reply-date {
|
||||||
|
margin-left: 0.5em;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply-name {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -115,6 +115,8 @@ layout: default
|
||||||
<div id="rss-sign-up">
|
<div id="rss-sign-up">
|
||||||
<span>For more <em>{{ page.category }}</em> posts like this, subscribe to my <a href={{'feed.xml' | relative_url}}>RSS feed</a></span>
|
<span>For more <em>{{ page.category }}</em> posts like this, subscribe to my <a href={{'feed.xml' | relative_url}}>RSS feed</a></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% include replies-section.html %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a class="u-url" href="{{ page.url | relative_url }}" hidden></a>
|
<a class="u-url" href="{{ page.url | relative_url }}" hidden></a>
|
||||||
|
|
Loading…
Reference in a new issue