assets/data/search.json in j1-template-2020.0.13 vs assets/data/search.json in j1-template-2020.0.14

- old
+ new

@@ -32,10 +32,20 @@ # Be careful changing the Liquid code. If the code is changed, check # the integrity of the YAML data created. Corrupted YAML data makes # the Javascript of SimpleJekyllSearch to fail (JSONLoader.js) and no # search functionality will be available for most UNCLEAR reasons. # ----------------------------------------------------------------------------- + # NOTE: + # Don't change the order of index generation (first pages, then posts). + # This is because the helper 'forloop.last' is NOT usable as NO + # 'site.pages.size' var is available. Instead, the pages array (site.pages) + # is iterated. + # ----------------------------------------------------------------------------- + # NOTE: + # For pages, NO excerpt is supported. As a replacement, the (page) + # description is used. + # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # ----------------------------------------------------------------------------- {% endcomment %} @@ -59,103 +69,94 @@ {% assign jekyll_search_settings = modules.jekyll_search.settings %} {% comment %} Set config options -------------------------------------------------------------------------------- {% endcomment %} {% assign jekyll_search_options = jekyll_search_defaults | merge: jekyll_search_settings %} +{% assign quick_search_config = site.data.modules.j1_jekyll_search %} +{% comment %} Set config data +-------------------------------------------------------------------------------- {% endcomment %} +{% assign result_target = quick_search_config.target %} +{% assign posts_num = site.posts.size %} + {% assign production = false %} {% if environment == 'prod' or environment == 'production' %} {% assign production = true %} {% endif %} -{% assign quick_search_config = site.data.modules.j1_jekyll_search %} -{% assign result_target = quick_search_config.target %} +{% comment %} Process 'pages' FIRST +-------------------------------------------------------------------------------- {% endcomment %} +{% for page in site.pages %} +{% if page.noindex %} {% continue %} {% endif %} +{% if page.url contains 'assets' or page.url contains '.json' or page.url contains '.txt' %} {% continue %} {% endif %} +{% if page.url contains '.html' %} {% continue %} {% endif %} +{% if page.url == '/'%} {% continue %} {% endif %} +{ + "title": "{{ page.title | escape }}", + "tagline": "{{ page.tagline }}", + {% if page.tags %} + "tags": "{{ page.tags | join: ', ' }}", + {% else %} + "tags": "", + {% endif %} + {% if page.index %} + "index": "{{ page.index | join: ', ' }}", + {% else %} + "index": "", + {% endif %} + {% if page.categories %} + "categories": "{{ page.categories | join: ', ' }}", + {% else %} + "categories": "", + {% endif %} + "url": "{{ site.baseurl }}{{ page.url }}", + "target": "{{ result_target }}", + {% if page.excerpt %} + "excerpt": "{{ page.excerpt | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...',' ...' }}" + {% else %} + "excerpt": "{{ page.description | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...',' ...' }}" + {% endif %} +}, +{% endfor %} -{% comment %} - Set posts count by posts_num. Indicates if a comma needs to be - set for valid JSON +{% comment %} Process 'posts' -------------------------------------------------------------------------------- {% endcomment %} -{% assign posts_num = site.posts.size %} +{% for post in site.posts %} +{% if post.noindex %} {% continue %} {% endif %} +{ + "title": "{{ post.title | strip }}", + "tagline": "{{ post.tagline | strip }}", + {% if post.tags %} + "tags": "{{ post.tags | join: ',' }}", + {% else %} + "tags": "", + {% endif %} + {% if post.index %} + "index": "{{ post.index | join: ',' }}", + {% else %} + "index": "", + {% endif %} + {% if post.categories %} + "categories": "{{ post.categories | join: ',' }}", + {% else %} + "categories": "", + {% endif %} + "date": "{{ post.date }}", + "url": "{{ site.baseurl }}{{ post.url }}", + "target": "{{ result_target }}", + {% if post.excerpt %} + "excerpt": "{{ post.excerpt | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...','  ...' }}" + {% else %} + "excerpt": "" + {% endif %} +}{% if forloop.last %}{% else %},{% endif %} +{% endfor %} - {% for post in site.posts %} - {% if post.noindex %} {% continue %} {% endif %} - { - "title": "{{ post.title | strip }}", - "tagline": "{{ post.tagline | strip }}", - {% if post.tags %} - "tags": "{{ post.tags | join: ',' }}", - {% else %} - "tags": "", - {% endif %} - {% if post.index %} - "index": "{{ post.index | join: ',' }}", - {% else %} - "index": "", - {% endif %} - {% if post.categories %} - "categories": "{{ post.categories | join: ',' }}", - {% else %} - "categories": "", - {% endif %} - "date": "{{ post.date }}", - "url": "{{ site.baseurl }}{{ post.url }}", - "target": "{{ result_target }}", - {% if post.excerpt %} - "excerpt": "{{ post.excerpt | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...','  ...' }}" - {% else %} - "excerpt": "" - {% endif %} - }{% if posts_num %},{% endif %} - {% endfor %} - - {% comment %} For unknown reason, loop for pages needs corrected - by page_offset. Helper forloop.last not usable. - ------------------------------------------------------------------------------ {% endcomment %} - - {% comment %} For pages, NO excerpt is supported (v3.8.5) - ------------------------------------------------------------------------------ {% endcomment %} - - {% assign page_offset = 2 %} - - {% for page in site.pages %} - {% if page.noindex %} {% continue %} {% endif %} - {% if page.url contains 'assets' or page.url contains '.json' or page.url contains '.txt' %} {% continue %} {% endif %} - {% if page.url contains '.html' %} {% continue %} {% endif %} - {% if page.url == '/'%} {% continue %} {% endif %} - { - "title": "{{ page.title | escape }}", - "tagline": "{{ page.tagline }}", - {% if page.tags %} - "tags": "{{ page.tags | join: ', ' }}", - {% else %} - "tags": "", - {% endif %} - {% if page.index %} - "index": "{{ page.index | join: ', ' }}", - {% else %} - "index": "", - {% endif %} - {% if page.categories %} - "categories": "{{ page.categories | join: ', ' }}", - {% else %} - "categories": "", - {% endif %} - "url": "{{ site.baseurl }}{{ page.url }}", - "target": "{{ result_target }}", - {% if page.excerpt %} - "excerpt": "{{ page.excerpt | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...',' ...' }}" - {% else %} - "excerpt": "{{ page.description | newline_to_br | strip_html | strip | newline_to_space | replace:'"','\"' | truncatewords: jekyll_search_options.result_truncate | replace:'....','  ...' | replace:':...',' ...' }}" - {% endif %} - }{% unless forloop.rindex0 == page_offset %},{% endunless %} - {% endfor %} {% endcapture %} - [ {% if production %} {{ cache | minifyJSON }} {% else %} {{ cache | strip_empty_lines }} {% endif %} ] - {% assign cache = nil %}