Simplify the 3 version quick links logic

This commit is contained in:
Robbie Trencheny 2019-03-09 19:08:51 -08:00
parent dccdc47aba
commit f675dc6b52
No known key found for this signature in database
GPG Key ID: 1E236BB235BF0021
2 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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 -%}
<p class='note'>
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.
<div class="filter-button-group">
<a href='#all' class="btn">All ({{tot}})</a>
<a href='#featured' class="btn featured">Featured</a>
<a href='#version/{{ current_version }}' class="btn added_in_current_version">Added in {{ current_version }} ({{ current_version_components_count }})</a>
<a href='#version/{{ added_one_ago_version }}' class="btn added_one_version_ago">Added in {{ added_one_ago_version }} ({{ one_ago_version_components_count }})</a>
<a href='#version/{{ added_two_ago_version }}' class="btn added_two_versions_ago">Added in {{ added_two_ago_version }} ({{ two_ago_version_components_count }})</a>
<a href='#version/{{ current_version.label }}' class="btn added_in_current_version">Added in {{ current_version.label }} ({{ current_version.new_components_count }})</a>
<a href='#version/{{ one_version_ago.label }}' class="btn added_one_version_ago">Added in {{ one_version_ago.label }} ({{ one_version_ago.new_components_count }})</a>
<a href='#version/{{ two_versions_ago.label }}' class="btn added_two_versions_ago">Added in {{ two_versions_ago.label }} ({{ two_versions_ago.new_components_count }})</a>
Added in <select name="versions">
{%- for group in components_by_version -%}
<optgroup label="{{ group.label }} ({{group.new_components_count}})">