Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _layouts/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ content }}

{% assign channel = page.channel | default: 'stable' %}
{% assign changelogs = site.changelogs | where: "channel", channel | reverse %}
{% assign changelogs = site.changelogs | where: "channel", channel | version_sort: "slug" | reverse %}
{% for item in changelogs %}
{% assign version = item.slug %}
<h1 id="{% if forloop.index == 1 %}nowchange{% else %}HMCL-{{ version }}{% endif %}" data-version="{{ version }}">HMCL {{ version }}</h1>
Expand Down
21 changes: 21 additions & 0 deletions _plugins/filter-version-sort.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module VersionSortFilter
def version_sort(input, property)
raise ArgumentError, "Cannot sort a null object." if input.nil?
raise ArgumentError, "Cannot sort an object with a null property." if property.nil?
raise ArgumentError, "Property #{property} is not an array of strings." unless valid_string_array?(input, property)

input.sort_by { |version| version_to_numbers(version[property]) }
end

private

def valid_string_array?(array, property)
array.is_a?(Array) && array.all? { |element| element[property].is_a?(String) }
end

def version_to_numbers(version_string)
version_string.split('.').map { |n| n.to_i }
end
end

Liquid::Template.register_filter(VersionSortFilter)