{{/* Get the last regular page for a given section recursively respecting the ordering of each sub-section. Expects a section -- NOT A REGULAR PAGE -- to be given as argument. Returns a regular page. Example usages from a regular page: - First page of comic : {{ partial "func/LastPageRecursive.html" .FirstSection }} - First page of chapter : {{ partial "func/LastPageRecursive.html" .Parent }} */}} {{/* As a note: using `index .FirstSection.RegularPagesRecursive.Reverse 0` would be unsafe. RegularPagesRecursive uses the default sort order on all found pages regardless of parent pages. Given the following pages, weight and title : - comic/ - chapter_1/: - page_1 (weight 10, title "Prologue - Page 1") - page_2 (weight 20, title "Prologue - Page 2") - ... - ... - chapter_7/: - page_1 (weight 10, title "Ending - Page 1") - page_2 (weight 20, title "Ending - Page 2") Using `index .FirstSection.RegularPagesRecursive 0` would give chapter_7/page_1 as first page! Hugo's ordering is done by *weight* desc., then *date* asc., then *title* desc., then *path* desc.. Thus, final order would be : - chapter_1/page_2: weight 20, title "Prologue - Page 2" - because 20 = 20 and P > E - chapter_2/page_2: weight 20, title "Ending - Page 2" - because 20 > 10 - chapter_1/page_1: weight 10, title "Prologue - Page 1" - because 10 = 10 and P > E - chapter_2/page_1: weight 10, title "Ending - Page 1" */}} {{ if .IsPage }} {{ errorf "'func/LastPageRecursive' page argument must be a section, not a regular page" }} {{ end }} {{ if eq .Pages.Len 0 }} {{ errorf "Section '%s' contains no pages!" .Path }} {{ end }} {{ $last_page := index .Pages.Reverse 0 }} {{ if $last_page.IsSection }} {{ $last_page = partial "func/LastPageRecursive.html" $last_page }} {{ end }} {{ return $last_page }}