From dbc9479fd5c262538d99d50fd3a648ee317d4a2a Mon Sep 17 00:00:00 2001 From: Daniel Schroeder Date: Tue, 19 Oct 2021 09:23:42 -0600 Subject: [PATCH] feat: Sort comments by date ascending (#3184) --- _includes/comments.html | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/_includes/comments.html b/_includes/comments.html index 4ff59e27..b27c893b 100644 --- a/_includes/comments.html +++ b/_includes/comments.html @@ -17,14 +17,23 @@
{% if site.data.comments[page.slug] %}

{{ site.data.ui-text[site.locale].comments_title | default: "Comments" }}

- {% assign comments = site.data.comments[page.slug] | sort %} + {% assign comments = site.data.comments[page.slug] %} + + + {% assign commentObjects = '' | split: '' %} + {% for comment in comments %} + {% assign commentObject = comment[1] %} + {% assign commentObjects = commentObjects | push: commentObject %} + {% endfor %} + {% assign comments = commentObjects | sort: "date" %} {% for comment in comments %} - {% assign email = comment[1].email %} - {% assign name = comment[1].name %} - {% assign url = comment[1].url %} - {% assign date = comment[1].date %} - {% assign message = comment[1].message %} + {% assign email = comment.email %} + {% assign name = comment.name %} + {% assign url = comment.url %} + {% assign date = comment.date %} + {% assign message = comment.message %} {% include comment.html index=forloop.index email=email name=name url=url date=date message=message %} {% endfor %} {% endif %} @@ -91,14 +100,23 @@
{% if site.data.comments[page.slug] %}

{{ site.data.ui-text[site.locale].comments_title | default: "Comments" }}

- {% assign comments = site.data.comments[page.slug] | sort %} + {% assign comments = site.data.comments[page.slug] %} + + + {% assign commentObjects = '' | split: '' %} + {% for comment in comments %} + {% assign commentObject = comment[1] %} + {% assign commentObjects = commentObjects | push: commentObject %} + {% endfor %} + {% assign comments = commentObjects | sort: "date" %} {% for comment in comments %} - {% assign email = comment[1].email %} - {% assign name = comment[1].name %} - {% assign url = comment[1].url %} - {% assign date = comment[1].date %} - {% assign message = comment[1].message %} + {% assign email = comment.email %} + {% assign name = comment.name %} + {% assign url = comment.url %} + {% assign date = comment.date %} + {% assign message = comment.message %} {% include comment.html index=forloop.index email=email name=name url=url date=date message=message %} {% endfor %} {% endif %}