{% assign index_array = “” | split: ',' %} {%- for page in site.html_pages -%} {%- unless page.exclude -%} {% unless page.name == 'index.html' or page.name == 'index.md' %} {%- assign page_url = page.url -%} {%- assign split_content = page.content | markdownify | split: '<h2' | splice: 1 -%}
{%- comment -%}Deal with h1 section{%- endcomment -%} {%- assign page_header = split_content.first | split: '</h1>' -%} {%- assign page_header = page_header.first | split: '“>' -%} {%- assign page_header = page_header.last | strip_html | newline_to_br | strip_newlines | replace: '<br />', ' ' | replace: '', '' | strip | smartify | normalize_whitespace -%} {%- assign header_section = '<h1' | append: split_content.first | strip_html | newline_to_br | strip_newlines | replace: '<br />', ' ' | replace: '', '' | strip | smartify | normalize_whitespace -%} {%- capture item -%} { ”title“: ”{{ page_header}}“, ”documentTitle“: ”{%- include_cached document-title.txt dir=page.dir info=“title” -%}“, ”url“: ”{{page_url | relative_url }}“, ”text“: ”{{ header_section }}“ } {% endcapture %} {%- assign index_array = index_array | push: item -%}
{%- comment -%}Then deal with h2 sections {%- endcomment -%} {%- for section in split_content offset:1 -%} {%- assign section_header_html = section | split: 'id=“' -%} {%- assign section_header_html = section_header_html | split: '”>' -%}
{%- comment -%}Get section id{%- endcomment -%} {%- assign section_id = section_header_html -%} {%- comment -%}Get section url{%- endcomment -%} {%- assign section_url = page_url | append: '#' | append: section_id -%}
{%- comment -%}Get section header{%- endcomment -%} {%- assign section_header = section_header_html | shift | join | split: '</h2' -%} {%- assign section_header = section_header | strip_html -%}
{%- comment -%}Get section body{%- endcomment -%} {%- assign full_section = '<h2 ' | append:section | strip_html | newline_to_br | strip_newlines | replace: '<br />', ' ' | replace: '', '' | strip | smartify | normalize_whitespace -%} {%- capture item -%} { “title”: “{{ section_header | smartify }}”, “documentTitle”: “{%- include_cached document-title.txt dir=page.dir info=”title“ -%}”, “url”: “{{ section_url | relative_url }}”, “text”: “{{ full_section }}” } {% endcapture %} {%- assign index_array = index_array | push: item -%}
{%- endfor -%} {%- endunless -%} {%- endunless -%} {%- endfor -%}
- {{ index_array | join: ','}}