@@ -17,14 +17,23 @@ <h4 class="page__comments-title">{{ comments_label }}</h4>
17
17
< div class ="js-comments ">
18
18
{% if site.data.comments[page.slug] %}
19
19
< h4 class ="page__comments-title "> {{ site.data.ui-text[site.locale].comments_title | default: "Comments" }}</ h4 >
20
- {% assign comments = site.data.comments[page.slug] | sort %}
20
+ {% assign comments = site.data.comments[page.slug] %}
21
21
22
+ <!-- In order to sort by date we must have an array of objects, not an array of arrays, so
23
+ create a new array of plain comment objects and then sort by the comment date. -->
24
+ {% assign commentObjects = '' | split: '' %}
22
25
{% for comment in comments %}
23
- {% assign email = comment[1].email %}
24
- {% assign name = comment[1].name %}
25
- {% assign url = comment[1].url %}
26
- {% assign date = comment[1].date %}
27
- {% assign message = comment[1].message %}
26
+ {% assign commentObject = comment[1] %}
27
+ {% assign commentObjects = commentObjects | push: commentObject %}
28
+ {% endfor %}
29
+ {% assign comments = commentObjects | sort: "date" %}
30
+
31
+ {% for comment in comments %}
32
+ {% assign email = comment.email %}
33
+ {% assign name = comment.name %}
34
+ {% assign url = comment.url %}
35
+ {% assign date = comment.date %}
36
+ {% assign message = comment.message %}
28
37
{% include comment.html index=forloop.index email=email name=name url=url date=date message=message %}
29
38
{% endfor %}
30
39
{% endif %}
@@ -91,14 +100,23 @@ <h4 class="page__comments-title">{{ site.data.ui-text[site.locale].comments_labe
91
100
< div class ="js-comments ">
92
101
{% if site.data.comments[page.slug] %}
93
102
< h4 class ="page__comments-title "> {{ site.data.ui-text[site.locale].comments_title | default: "Comments" }}</ h4 >
94
- {% assign comments = site.data.comments[page.slug] | sort %}
103
+ {% assign comments = site.data.comments[page.slug] %}
104
+
105
+ <!-- In order to sort by date we must have an array of objects, not an array of arrays, so
106
+ create a new array of plain comment objects and then sort by the comment date. -->
107
+ {% assign commentObjects = '' | split: '' %}
108
+ {% for comment in comments %}
109
+ {% assign commentObject = comment[1] %}
110
+ {% assign commentObjects = commentObjects | push: commentObject %}
111
+ {% endfor %}
112
+ {% assign comments = commentObjects | sort: "date" %}
95
113
96
114
{% for comment in comments %}
97
- {% assign email = comment[1] .email %}
98
- {% assign name = comment[1] .name %}
99
- {% assign url = comment[1] .url %}
100
- {% assign date = comment[1] .date %}
101
- {% assign message = comment[1] .message %}
115
+ {% assign email = comment.email %}
116
+ {% assign name = comment.name %}
117
+ {% assign url = comment.url %}
118
+ {% assign date = comment.date %}
119
+ {% assign message = comment.message %}
102
120
{% include comment.html index=forloop.index email=email name=name url=url date=date message=message %}
103
121
{% endfor %}
104
122
{% endif %}
0 commit comments