From f675dc6b52ba750e4d98a27c881fce77af4c8041 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Sat, 9 Mar 2019 19:08:51 -0800 Subject: [PATCH] Simplify the 3 version quick links logic --- plugins/filters.rb | 10 ++++++++++ source/components/index.html | 17 ++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/filters.rb b/plugins/filters.rb index c72f148290a..82875e0d46e 100644 --- a/plugins/filters.rb +++ b/plugins/filters.rb @@ -118,6 +118,16 @@ module Jekyll { "label" => v[0], "versions" => v[1], "new_components_count" => total_new_components, "sort_key" => sort_key } }.sort_by { |v| v["sort_key"] }.reverse end + + # Get version N behind current + # input is output of group_components_by_release + def version_behind(input, n) + input.each do |group| + if group["versions"].length > n + return group["versions"][n] + end + end + end end end diff --git a/source/components/index.html b/source/components/index.html index 0dff8fcaef7..fda87405be1 100644 --- a/source/components/index.html +++ b/source/components/index.html @@ -28,14 +28,9 @@ regenerate: false {%- assign components = site.components | sort: 'title' -%} {%- assign components_by_version = site.components | group_components_by_release -%} {%- assign categories = components | map: 'ha_category' | join: ',' | join: ',' | split: ',' | uniq | sort -%} -{%- capture current_version -%}{{ site.current_major_version }}.{{ site.current_minor_version }}{% endcapture -%} -{%- assign added_one_ago_minor_version = site.current_minor_version|minus: 1 -%} -{%- capture added_one_ago_version -%}{{ site.current_major_version }}.{{ added_one_ago_minor_version }}{% endcapture -%} -{%- assign added_two_ago_minor_version = site.current_minor_version|minus: 2 -%} -{%- capture added_two_ago_version -%}{{ site.current_major_version }}.{{ added_two_ago_minor_version }}{% endcapture -%} -{%- assign current_version_components_count = site.components | where: 'ha_release', current_version | size -%} -{%- assign one_ago_version_components_count = site.components | where: 'ha_release', added_one_ago_version | size -%} -{%- assign two_ago_version_components_count = site.components | where: 'ha_release', added_two_ago_version | size -%} +{%- assign current_version = components_by_version[0]["versions"][0] -%} +{%- assign one_version_ago = components_by_version | version_behind: 1 -%} +{%- assign two_versions_ago = components_by_version | version_behind: 2 -%}

Support for these components is provided by the Home Assistant community. @@ -46,9 +41,9 @@ Support for these components is provided by the Home Assistant community.

All ({{tot}}) Featured - Added in {{ current_version }} ({{ current_version_components_count }}) - Added in {{ added_one_ago_version }} ({{ one_ago_version_components_count }}) - Added in {{ added_two_ago_version }} ({{ two_ago_version_components_count }}) + Added in {{ current_version.label }} ({{ current_version.new_components_count }}) + Added in {{ one_version_ago.label }} ({{ one_version_ago.new_components_count }}) + Added in {{ two_versions_ago.label }} ({{ two_versions_ago.new_components_count }}) Added in