sort_natural

功能說明
使用自然排序法(case-insensitive,按字母與數字邏輯排序)對陣列進行排序。若陣列元素為物件,可指定屬性名稱。


語法

{{ 陣列 | sort_natural }}
{{ 陣列 | sort_natural: "屬性名稱" }}

範例

{{ ["file10", "file2", "file1"] | sort_natural }}
["file1", "file2", "file10"]
{% assign books = 
  [
    { "title": "Volume 10" },
    { "title": "Volume 2" },
    { "title": "Volume 1" }
  ]
%}

{{ books | sort_natural: "title" | map: "title" }}
["Volume 1", "Volume 2", "Volume 10"]