module

Hwaro::Utils::SortUtils

Constants

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

Stand-in date for an undated page where a timestamp must be printed (feed <updated>); never used for ordering.

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, then date. An undated page sorts after every dated one — including pre-1970 dates, which a 1970 stand-in date used to put below undated pages. Returns negative if a should come first, positive if b should come first

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

Like compare_by_date, but on the publish date alone: a revised post (updated) keeps its place in a chronological archive (gh#865).

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
compare_term_names(a : String, b : String) : Int32

Compare two taxonomy term names alphabetically, ignoring case ("acp" < "SRI" < "Zola"); byte order breaks ties so "Go" and "go" still order deterministically.

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", "published", "title", "weight"

Source
sort_term_names(names : Array(String), by_count : Bool, & : String -> Int32) : Array(String)

Taxonomy term order (terms_sort_by): by name, or with by_count by the block's page count descending with the name order as tiebreak.

Source