module

Hwaro::Utils::SortUtils

Constants

FALLBACK_DATE = Time.utc(1970, 1, 1)

Default fallback date used when a page has no date set

Instance methods

compare_by_date(a : Models::Page, b : Models::Page) : Int32

Compare two pages by date (newest first by default)

Uses updated date if available, falls back to date, then FALLBACK_DATE Returns negative if a should come first, positive if b should come first

Source
compare_by_title(a : Models::Page, b : Models::Page) : Int32

Compare two pages by title alphabetically (A-Z)

Source
compare_by_weight(a : Models::Page, b : Models::Page) : Int32

Compare two pages by weight value (lower weight first)

Source
sort_by_date(pages : Array(Models::Page), reverse : Bool = false) : Array(Models::Page)

Sort pages by date (newest first)

Source
sort_by_title(pages : Array(Models::Page), reverse : Bool = false) : Array(Models::Page)

Sort pages by title alphabetically

Source
sort_by_weight(pages : Array(Models::Page), reverse : Bool = false) : Array(Models::Page)

Sort pages by weight

Source
sort_pages(pages : Array(Models::Page), sort_by : String = "date", reverse : Bool = false) : Array(Models::Page)

Generic page sorting with specified criteria

Supported sort_by values: "date", "title", "weight"

Source