Rename Jekyll components collection to integrations

This commit is contained in:
Franck Nijhof 2019-09-29 22:03:21 +02:00
parent 57c6dec6c2
commit 611115e1ea
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 217 additions and 184 deletions

View File

@ -63,7 +63,7 @@ titlecase: true # Converts page and post titles to titlecase
# page_asides: # page_asides:
collections: collections:
components: integrations:
output: true output: true
cookbook: cookbook:
output: true output: true

View File

@ -10,22 +10,22 @@ regenerate: false
{%- comment -%}Can't use where to count nil because of https://github.com/jekyll/jekyll/issues/6038{%- endcomment -%} {%- comment -%}Can't use where to count nil because of https://github.com/jekyll/jekyll/issues/6038{%- endcomment -%}
{%- assign tot = 0 -%} {%- assign tot = 0 -%}
{%- for comp in site.components -%} {%- for comp in site.integrations -%}
{%- if comp.ha_category -%} {%- if comp.ha_category -%}
{%- if comp.ha_category.first -%} {%- if comp.ha_category.first -%}
{%- assign tot = tot | plus: comp.ha_category.size -%} {%- assign tot = tot | plus: comp.ha_category.size -%}
{%- else -%} {%- else -%}
{%- assign tot = tot | plus: 1 -%} {%- assign tot = tot | plus: 1 -%}
{%- endif -%} {%- endif -%}
{%- endif %} {%- endif %}
{%- endfor -%} {%- endfor -%}
{%- assign components = site.components | sort: 'title' -%} {%- assign components = site.integrations | sort: 'title' -%}
{%- assign components_by_version = site.components | group_components_by_release -%} {%- assign components_by_version = site.integrations | group_components_by_release -%}
{%- assign categories = components | map: 'ha_category' | join: ',' | join: ',' | split: ',' | uniq | sort -%} {%- assign categories = components | map: 'ha_category' | join: ',' | join: ',' | split: ',' | uniq | sort -%}
<p class='note'> <p class='note'>
Support for these integrations is provided by the Home Assistant community. Support for these integrations is provided by the Home Assistant community.
</p> </p>
<div class="grid"> <div class="grid">
<div class="grid__item one-sixth lap-one-whole palm-one-whole"> <div class="grid__item one-sixth lap-one-whole palm-one-whole">
@ -38,17 +38,18 @@ Support for these integrations is provided by the Home Assistant community.
{%- for group in components_by_version -%} {%- for group in components_by_version -%}
<optgroup label="{{ group.label }} ({{group.new_components_count}})"> <optgroup label="{{ group.label }} ({{group.new_components_count}})">
{%- for version in group.versions -%} {%- for version in group.versions -%}
<option value="#version/{{ version.label }}">{{ version.label }} ({{ version.new_components_count }})</option> <option value="#version/{{ version.label }}">{{ version.label }} ({{ version.new_components_count }})
</option>
{%- endfor -%} {%- endfor -%}
</optgroup> </optgroup>
{%- endfor -%} {%- endfor -%}
</select></div> </select></div>
{%- for category in categories -%} {%- for category in categories -%}
{%- assign components_count = components | where: 'ha_category', category | size -%} {%- assign components_count = components | where: 'ha_category', category | size -%}
{%- if category and category != 'Other' and components_count != 0 -%} {%- if category and category != 'Other' and components_count != 0 -%}
<a href='#{{ category | slugify }}' class="btn">{{ category }} ({{ components_count }})</a> <a href='#{{ category | slugify }}' class="btn">{{ category }} ({{ components_count }})</a>
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
<a href='#other' class="btn">Other ({{ components | where: 'ha_category', 'Other' | size }})</a> <a href='#other' class="btn">Other ({{ components | where: 'ha_category', 'Other' | size }})</a>
</div> </div>
@ -69,7 +70,7 @@ Support for these integrations is provided by the Home Assistant community.
{% raw %} {% raw %}
<script id="component-template" type="text/x-custom-template"> <script id="component-template" type="text/x-custom-template">
{{#components}} {{#components}}
<a href="{{url}}" class="option-card"> <a href="{{url}}" class="option-card">
<div class="img-container">{{{image}}}</div> <div class="img-container">{{{image}}}</div>
<div class='title'>{{title}}</div> <div class='title'>{{title}}</div>
@ -83,38 +84,69 @@ Support for these integrations is provided by the Home Assistant community.
{% endraw %} {% endraw %}
<script type="text/javascript"> <script type="text/javascript">
// This object contains all components we have // This object contains all components we have
var allComponents = [ var allComponents = [{
{%- for component in components -%} % -
{%- if component.ha_category -%} for component in components - %
{%- assign sliced_version = component.ha_release | split: '.' -%} } {
{%- assign minor_version = sliced_version[1]|plus: 0 -%} % -
{%- assign major_version = sliced_version[0]|plus: 0 -%} if component.ha_category - %
{%- assign featured_first = true -%} } {
{%- for ha_category in component.ha_category -%} % -assign sliced_version = component.ha_release | split: '.' - %
{url:"{{ component.url }}", title:"{{component.title}}", cat:"{{ha_category | slugify}}", featured: {% if component.featured and featured_first %}true{% else %}false{% endif %}, v: "{{major_version}}.{{minor_version}}", logo: "{{component.logo}}"}, } {
{%- assign featured_first = false -%} % -assign minor_version = sliced_version[1] | plus: 0 - %
{%- endfor -%} } {
{% endif -%} % -assign major_version = sliced_version[0] | plus: 0 - %
{%- endfor -%} } {
% -assign featured_first = true - %
} {
% -
for ha_category in component.ha_category - %
} {
url: "{{ component.url }}",
title: "{{component.title}}",
cat: "{{ha_category | slugify}}",
featured: {
%
if component.featured and featured_first %
}
true {
%
else %
}
false {
% endif %
},
v: "{{major_version}}.{{minor_version}}",
logo: "{{component.logo}}"
},
{
% -assign featured_first = false - %
} {
% -endfor - %
} {
% endif - %
} {
% -endfor - %
}
false false
]; ];
allComponents.pop(); // remove placeholder element at the end allComponents.pop(); // remove placeholder element at the end
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function () {
var template = $('#component-template').html(); var template = $('#component-template').html();
Mustache.parse(template); // make future calls to render faster Mustache.parse(template); // make future calls to render faster
function init() { function init() {
// do the lowerCase transformation once // do the lowerCase transformation once
for (i=0; i < (allComponents.length); i++) { for (i = 0; i < (allComponents.length); i++) {
allComponents[i].titleLC = allComponents[i].title.toLowerCase(); allComponents[i].titleLC = allComponents[i].title.toLowerCase();
allComponents[i].catLC = allComponents[i].cat.toLowerCase(); allComponents[i].catLC = allComponents[i].cat.toLowerCase();
} }
// sort the components alphabetically // sort the components alphabetically
allComponents.sort(function(a, b){ allComponents.sort(function (a, b) {
return a.titleLC.localeCompare(b.titleLC); return a.titleLC.localeCompare(b.titleLC);
}); });
@ -165,21 +197,21 @@ allComponents.pop(); // remove placeholder element at the end
if (hash.indexOf('#search/') === 0) { if (hash.indexOf('#search/') === 0) {
// search through title and category // search through title and category
search = decodeURIComponent(hash).substring(8).toLowerCase(); search = decodeURIComponent(hash).substring(8).toLowerCase();
filter = function(comp) { filter = function (comp) {
return (comp.titleLC.indexOf(search) !== -1) || return (comp.titleLC.indexOf(search) !== -1) ||
(comp.catLC.indexOf(search) !== -1); (comp.catLC.indexOf(search) !== -1);
}; };
} else if(hash === '#featured' || hash === '') { } else if (hash === '#featured' || hash === '') {
// only show those with featured = true // only show those with featured = true
filter = function(comp) { filter = function (comp) {
return comp.featured; return comp.featured;
}; };
} else if(hash.indexOf('#version/') === 0) { } else if (hash.indexOf('#version/') === 0) {
// compare against a version // compare against a version
search = decodeURIComponent(hash).substring(9).toLowerCase(); search = decodeURIComponent(hash).substring(9).toLowerCase();
filter = function(comp) { filter = function (comp) {
// compare version string against version js // compare version string against version js
return comp.v === search; return comp.v === search;
}; };
@ -187,13 +219,13 @@ allComponents.pop(); // remove placeholder element at the end
} else { } else {
// regular filter categories // regular filter categories
search = hash.substring(1); search = hash.substring(1);
filter = function(comp) { filter = function (comp) {
return comp.catLC === search; return comp.catLC === search;
}; };
} }
// filter all components using the filter function // filter all components using the filter function
for (i=0; i < (allComponents.length); i++) { for (i = 0; i < (allComponents.length); i++) {
if (filter(allComponents[i])) { if (filter(allComponents[i])) {
data.components.push(allComponents[i]); data.components.push(allComponents[i]);
} }
@ -219,7 +251,7 @@ allComponents.pop(); // remove placeholder element at the end
} }
// update view by filter selection // update view by filter selection
jQuery('.filter-button-group a').click(function() { jQuery('.filter-button-group a').click(function () {
updateHash(this.getAttribute('href')); updateHash(this.getAttribute('href'));
applyFilter(); applyFilter();
@ -227,7 +259,7 @@ allComponents.pop(); // remove placeholder element at the end
}); });
// update view on select change // update view on select change
jQuery('select').change(function() { jQuery('select').change(function () {
updateHash(this.value); updateHash(this.value);
applyFilter(); applyFilter();
@ -239,9 +271,10 @@ allComponents.pop(); // remove placeholder element at the end
*/ */
function debounce(func, wait, immediate) { function debounce(func, wait, immediate) {
var timeout; var timeout;
return function() { return function () {
var context = this, args = arguments; var context = this,
var later = function() { args = arguments;
var later = function () {
timeout = null; timeout = null;
if (!immediate) { if (!immediate) {
func.apply(context, args); func.apply(context, args);
@ -257,7 +290,7 @@ allComponents.pop(); // remove placeholder element at the end
}; };
// update view by search text // update view by search text
$('.component-search input').keyup(debounce(function() { $('.component-search input').keyup(debounce(function () {
var text = $(this).val(); var text = $(this).val();
// sanitize input // sanitize input
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '').trim(); text = text.replace(/[(\?|\&\{\}\(\))]/gi, '').trim();
@ -269,7 +302,7 @@ allComponents.pop(); // remove placeholder element at the end
window.addEventListener('hashchange', applyFilter); window.addEventListener('hashchange', applyFilter);
applyFilter(); applyFilter();
})(); })();
</script> </script>
<noscript> <noscript>