{{/* Gets the previous leaf section of a page / section. "Leaf section" means "section without sub-sections". "Previous" is regarding default ordering, respecting each intermediate section ordering. Expects a page or a section as argument. Returns a Section if it exists, 'false' if there is no such section. Here is a small example of what this function would return : - comic/ -> return false - ACT_1/ -> return false - chapter_1/ -> return false - P01 -> return false - P02 -> return false - chapter_2/ -> return `chapter_1/` - P03 -> return `chapter_2/` - P04 -> return `chapter_2/` - ACT_2/ -> return `chapter_2/` - chapter_3/ -> return `chapter_2/` - P05 -> return `chapter_2/` - P06 -> return `chapter_2/` - chapter_4/ -> return `chapter_3/` - P07 -> return `chapter_3/` - P08 -> return `chapter_3/` Example usage: {{ partial "func/PrevLeafSection.html" . }} */}} {{ $prev_leaf_section := false }} {{ $current_section := . }} {{/* A regular page can ve given as argument instead of a section */}} {{ if .IsPage }} {{ $current_section = .Parent }} {{ end }} {{/* if the root was reached, there is no possible previous section */}} {{ if not ($current_section.FirstSection.Eq $current_section) }} {{/* Get the previous sibling section. We need to actually reverse the ordering because because Next / Prev use *descending* weight ordering. */}} {{ $sibling_sections := $current_section.Parent.Sections.Reverse }} {{ with $sibling_sections.Prev $current_section }} {{/* Sibling found, get the last leaf section in case there is more than one level of depth */}} {{ $prev_leaf_section = partial "func/LastSectionRecursive.html" . }} {{ else }} {{/* No sibling found, try again with parent */}} {{ $prev_leaf_section = partial "func/PrevLeafSection.html" $current_section.Parent }} {{ end }} {{ end }} {{ return $prev_leaf_section }}