namespace :search do desc 'Generate the files needed for search functionality' task :init do puts 'Creating search data json file...' mkdir_p 'assets/js' touch 'assets/js/zzzz-search-data.json' puts 'Done.' puts 'Generating content...' File.open('assets/js/zzzz-search-data.json', 'w') do |f| f.puts '--- permalink: /assets/js/search-data.json --- { {%- assign i = 0 -%} {% for page in site.html_pages %} {%- if page.title and page.search_exclude != true -%} {%- assign page_content = page.content -%} {%- assign heading_level = site.search.heading_level | default: 2 -%} {%- for j in (2..heading_level) -%} {%- assign tag = \'\' -%} {%- assign title = titleAndContent[0] | replace_first: \'>\', \'

\' | split: \'

\' -%} {%- assign title = title[1] | strip_html -%} {%- assign content = titleAndContent[1] -%} {%- assign url = page.url -%} {%- if title == page.title and parts[0] == \'\' -%} {%- assign title_found = true -%} {%- else -%} {%- assign id = titleAndContent[0] -%} {%- assign id = id | split: \'id="\' -%} {%- if id.size == 2 -%} {%- assign id = id[1] -%} {%- assign id = id | split: \'"\' -%} {%- assign id = id[0] -%} {%- capture url -%}{{ url | append: \'#\' | append: id }}{%- endcapture -%} {%- endif -%} {%- endif -%} {%- unless i == 0 -%},{%- endunless -%} "{{ i }}": { "doc": {{ page.title | jsonify }}, "title": {{ title | jsonify }}, "content": {{ content | replace: \'