{# Recursively render a page's headings table of contents #} {%- macro render_book_page_toc(children, indents) -%} {%- set tabs = "" -%} {%- for i in range(end = indents) -%} {%- set_global tabs = tabs ~ " " -%} {%- endfor -%} {%- if children | length > 0 %} {{ tabs }} {%- endif -%} {%- endmacro render_book_page_toc -%} {# Recursively render a book's chapters table of contents #} {%- macro render_book_outline(parent, current_path, index, indents) -%} {#- Setup -#} {%- set chapters = parent.pages | default(value = []) -%} {%- if index == 0 -%} {%- set_global chapters = [parent] -%} {%- else -%} {%- for subsection_path in parent.subsections -%} {%- set_global chapters = chapters | concat(with = get_section(path = subsection_path)) -%} {%- endfor -%} {%- endif -%} {%- if index > 0 -%} {%- set_global chapters = chapters | sort(attribute = "extra.order") -%} {%- endif -%} {#- End of setup -#} {%- set tabs = "" -%} {%- for i in range(end = indents) -%} {%- set_global tabs = tabs ~ " " -%} {%- endfor -%} {%- if chapters | length > 0 %} {{ tabs }} {%- endif -%} {%- endmacro render_book_outline -%} {# Recursively flatten the book outline to a string for sequential navigation #} {%- macro flatten_book_outline(section) -%} {#- Setup -#} {%- set items = [] -%} {%- if section.pages -%} {%- set_global items = items | concat(with = section.pages) -%} {%- endif -%} {%- if section.subsections -%} {%- for subsection_path in section.subsections -%} {%- set subsection = get_section(path = subsection_path) -%} {%- set_global items = items | concat(with = subsection) -%} {%- endfor -%} {%- endif -%} {%- set items = items | sort(attribute = "extra.order") -%} {#- End of setup -#} {%- for item in items -%} {{ item.path }},,,,,{{ item.title }};;;;; {%- if item.pages or item.subsections -%} {{ self::flatten_book_outline(section = item) }} {%- endif -%} {%- endfor -%} {%- endmacro flatten_book_outline -%}