Partially fix replies

This commit is contained in:
Lewis Dale 2023-10-09 08:57:48 +01:00
parent 640179587c
commit 8b6a712a62
2 changed files with 17 additions and 12 deletions

View File

@ -52,6 +52,7 @@ class PostCache {
const comments = [...await this.fetchCommentsByType(), ...await this.fetchCommentsByType("webmention")]; const comments = [...await this.fetchCommentsByType(), ...await this.fetchCommentsByType("webmention")];
comments.forEach(comment => { comments.forEach(comment => {
console.log(comment.post);
if (this.posts[comment.post]) { if (this.posts[comment.post]) {
this.posts[comment.post].comments[comment.id] = comment; this.posts[comment.post].comments[comment.id] = comment;
} }
@ -94,7 +95,7 @@ const mapComment = comment => ({
url: comment.meta.semantic_linkbacks_author_url, url: comment.meta.semantic_linkbacks_author_url,
}, },
content: comment.content.rendered, content: comment.content.rendered,
canonical: comment.meta.semantic_linkbacks_canonical, canonical: comment.meta.url,
date: comment.date, date: comment.date,
}); });
@ -103,19 +104,24 @@ module.exports = async () => {
const cache = new PostCache(); const cache = new PostCache();
await cache.fetchLatest(); await cache.fetchLatest();
return Object.values(cache.posts) const posts = Object.values(cache.posts)
.sort(dateSort) .sort(dateSort)
.map(post => ({ .map(post => ({
...post, ...post,
comments: Object.values(post.comments) comments: Object.values(post.comments)
.sort(dateSort) .sort(dateSort)
.reduce((comments, comment) => { .reduce((comments, comment) => {
if (!comments[comment.meta.semantic_linkbacks_type]) { if (!comments[comment.type]) {
comments[comment.meta.semantic_linkbacks_type] = []; comments[comment.type] = [];
} }
comments[comment.meta.semantic_linkbacks_type].push(mapComment(comment)); comments[comment.type].push(mapComment(comment));
return comments; return comments;
}, { like: [], reply: [], repost: [] }) }, { like: [], reply: [], repost: [] })
})); }));
console.log(cache.posts[24].comments);
console.log(posts.find(post => post.id === 24)?.comments);
return posts;
}; };

View File

@ -30,6 +30,7 @@ eleventyComputed:
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if post.comments.repost | length %} {% if post.comments.repost | length %}
<div class="stack-xs"> <div class="stack-xs">
<h3 class="block w-full">Reposts</h3> <h3 class="block w-full">Reposts</h3>
@ -44,20 +45,18 @@ eleventyComputed:
</div> </div>
{% endif %} {% endif %}
{% if post.comments.reply | length %} {% if post.comments.comment | length %}
<div class="stack-xs"> <div class="stack-xs">
<h3 class="block w-full">Replies</h3> <h3 class="block w-full">Replies</h3>
<ol class="stack-md"> <ol class="stack-md">
{% for reply in post.comments.reply | reverse %} {% for reply in post.comments.comment | reverse %}
<li class="sidebar items-center"> <li class="sidebar items-center">
<a href="{{ like.author.url }}" class="self-start" rel="noreferrer" target="_blank">
<img src="{{ reply.author.avatars["96"] }}" alt="{{ reply.author.name }}" class="max-w-[4rem] box" />
</a>
<div class="stack-2xs basis-[50ch]"> <div class="stack-2xs basis-[50ch]">
{% set date = reply.date | parseDate %} {% set date = reply.date | parseDate %}
<h4>{{ reply.author.name }} <span class="font-normal">on</span> {{ date | dateDisplay }} <span class="font-normal">at</span> {{ date | timeDisplay }}</h4> <h4><a href="{{ reply.author.url }}" rel="noreferrer" target="_blank">{{ reply.author.name }}</a> <span class="font-normal">on</span> {{ date | dateDisplay }} <span class="font-normal">at</span> {{ date | timeDisplay }}</h4>
<a href="{{ reply.canonical }}" rel="noreferrer" target="_blank">Original comment</a> <a href="{{ reply.canonical }}" rel="noreferrer" target="_blank">Original comment</a>
<p>{{ reply.content | safe }}</p> <p>{{ reply.content | safe }}</p>
</div> </div>