From 8b6a712a623a01b1ec46c247e7a2c6a6ff087ce7 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Mon, 9 Oct 2023 08:57:48 +0100 Subject: [PATCH] Partially fix replies --- src/_data/posts.js | 18 ++++++++++++------ src/_includes/post.njk | 11 +++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/_data/posts.js b/src/_data/posts.js index f3643c6..00bb331 100644 --- a/src/_data/posts.js +++ b/src/_data/posts.js @@ -52,6 +52,7 @@ class PostCache { const comments = [...await this.fetchCommentsByType(), ...await this.fetchCommentsByType("webmention")]; comments.forEach(comment => { + console.log(comment.post); if (this.posts[comment.post]) { this.posts[comment.post].comments[comment.id] = comment; } @@ -94,7 +95,7 @@ const mapComment = comment => ({ url: comment.meta.semantic_linkbacks_author_url, }, content: comment.content.rendered, - canonical: comment.meta.semantic_linkbacks_canonical, + canonical: comment.meta.url, date: comment.date, }); @@ -102,20 +103,25 @@ const mapComment = comment => ({ module.exports = async () => { const cache = new PostCache(); await cache.fetchLatest(); - - return Object.values(cache.posts) + + const posts = Object.values(cache.posts) .sort(dateSort) .map(post => ({ ...post, comments: Object.values(post.comments) .sort(dateSort) .reduce((comments, comment) => { - if (!comments[comment.meta.semantic_linkbacks_type]) { - comments[comment.meta.semantic_linkbacks_type] = []; + if (!comments[comment.type]) { + comments[comment.type] = []; } - comments[comment.meta.semantic_linkbacks_type].push(mapComment(comment)); + comments[comment.type].push(mapComment(comment)); return comments; }, { like: [], reply: [], repost: [] }) })); + + + console.log(cache.posts[24].comments); + console.log(posts.find(post => post.id === 24)?.comments); + return posts; }; diff --git a/src/_includes/post.njk b/src/_includes/post.njk index f531bf8..cbb0de5 100644 --- a/src/_includes/post.njk +++ b/src/_includes/post.njk @@ -30,6 +30,7 @@ eleventyComputed: {% endif %} + {% if post.comments.repost | length %}

Reposts

@@ -44,20 +45,18 @@ eleventyComputed:
{% endif %} - {% if post.comments.reply | length %} + {% if post.comments.comment | length %}

Replies

    - {% for reply in post.comments.reply | reverse %} + {% for reply in post.comments.comment | reverse %}