From c8a8ce331440e76ff21ae93d539c22d7e34f6ee1 Mon Sep 17 00:00:00 2001
From: Ben Goldhaber <Goldhaber.Ben@gmail.com>
Date: Tue, 4 Jun 2019 18:02:56 -0700
Subject: [PATCH] Fix trailing comma bug in search-data.json

If you exclude the last page in the site.html_pages through exclude_true you end up violating the assumption in the for loop that the last page won't have a trailing comma. This breaks the json data that is served to the front end.

I removed the forloop.last check and instead assign a temporary variable to check for the first non-excluded page, and then add the comma before the next non-excluded entry.
---
 assets/js/search-data.json | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/assets/js/search-data.json b/assets/js/search-data.json
index 49cbc9dc..3d57eb3d 100644
--- a/assets/js/search-data.json
+++ b/assets/js/search-data.json
@@ -1,12 +1,14 @@
 ---
 ---
 {
-  {% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
-    "id": "{{ forloop.index0 }}",
-    "title": "{{ page.title | replace: '&amp;', '&' }}",
-    "content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```'  | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
-    "url": "{{ page.url | absolute_url }}",
-    "relUrl": "{{ page.url }}"
-  }{% unless forloop.last %},{% endunless %}
-  {% endif %}{% endfor %}
+  {% assign comma = false %}
+    {% for page in site.html_pages %}{% if page.search_exclude != true %}{% if comma == true%},{% endif %}
+    "{{ forloop.index0 }}": {
+      "id": "{{ forloop.index0 }}",
+      "title": "{{ page.title | replace: '&amp;', '&' }}",
+      "content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```'  | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
+      "url": "{{ page.url | absolute_url }}",
+      "relUrl": "{{ page.url }}"
+    }{% assign comma = true %}
+    {% endif %}{% endfor %}
 }
-- 
GitLab