1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,38 @@ |
1 |
+## |
|
2 |
+# Flattens the icons object to a one-dimensional array of possible search terms. |
|
3 |
+ |
|
4 |
+require 'set' |
|
5 |
+ |
|
6 |
+module Jekyll |
|
7 |
+ module FlattenArray |
|
8 |
+ def flattenIconFilters(icons) |
|
9 |
+ flattened = Set.new |
|
10 |
+ icons.each do |icon| |
|
11 |
+ toAdd = [] |
|
12 |
+ |
|
13 |
+ toAdd.push(icon["class"].downcase) # Add class as a filter value |
|
14 |
+ |
|
15 |
+ # Add any existing aliases as a filter value |
|
16 |
+ if not icon["aliases"].nil? |
|
17 |
+ icon["aliases"].each do |iconAlias| |
|
18 |
+ toAdd.push(iconAlias.downcase) |
|
19 |
+ end |
|
20 |
+ end |
|
21 |
+ |
|
22 |
+ # Add any existing filters as a filter value |
|
23 |
+ if not icon["filter"].nil? |
|
24 |
+ icon["filter"].each do |iconFilter| |
|
25 |
+ toAdd.push(iconFilter.downcase) |
|
26 |
+ end |
|
27 |
+ end |
|
28 |
+ flattened.merge(toAdd) |
|
29 |
+ |
|
30 |
+ print toAdd if toAdd.include? true |
|
31 |
+ print toAdd if toAdd.include? false |
|
32 |
+ end |
|
33 |
+ return flattened.to_a # .to_a because we can't jsonify a <Set> |
|
34 |
+ end |
|
35 |
+ end |
|
36 |
+end |
|
37 |
+ |
|
38 |
+Liquid::Template.register_filter(Jekyll::FlattenArray) |