diff --git a/_layouts/formula_json.json b/_layouts/formula_json.json index 2f6da6afa2c7..bff24bc43041 100644 --- a/_layouts/formula_json.json +++ b/_layouts/formula_json.json @@ -1,104 +1,46 @@ --- --- -{%- assign formula_path = page.dir | split: "/" -%} -{%- assign formula_path = formula_path[2] -%} -{%- if formula_path == "formula-linux" -%} - {%- assign analytics_path = "analytics-linux" -%} - {%- assign analytics_data_source = "linuxbrew-core" -%} -{%- else -%} - {%- assign analytics_path = "analytics" -%} - {%- assign analytics_data_source = "homebrew-core" -%} -{%- endif -%} {%- assign full_name = page.name | remove: ".json" -%} -{%- assign name = full_name | remove: "@" | remove: "." | replace: "+", "_" -%} -{%- assign formula = site.data[formula_path][name] -%} +{%- assign data_name = full_name | remove: "@" | remove: "." | replace: "+", "_" -%} +{%- assign formula = site.data.formula[data_name] -%} +{%- assign sources = "analytics, analytics-linux" | split: ", " -%} +{%- assign categories = "install, install-on-request, build-error" | split: ", " -%} +{%- assign intervals = "30d, 90d, 365d" | split: ", " -%} { {%- for key_value in formula -%} {{ key_value[0] | jsonify }}:{{ key_value[1] | jsonify }}, {%- endfor -%} -"analytics":{"install":{"30d":{ -{%- if site.data[analytics_path].install[analytics_data_source]["30d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install[analytics_data_source]["30d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} +{%- for source in sources -%} + "{{ source }}":{ + {%- for category in categories -%} + "{{ category | replace: "-", "_" }}":{ + {%- for interval in intervals -%} + "{{ interval }}":{ + {%- if site.data[source][category].homebrew-core[interval].formulae[full_name].size > 0 -%} + {%- for fa in site.data[source][category].homebrew-core[interval].formulae[full_name] -%} + {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} + {%- unless forloop.last -%} + , + {%- endunless -%} + {%- endfor -%} + {%- else -%} + {{ full_name | jsonify }}:0 + {%- endif -%} + } + {%- if category == "build-error" -%} + {%- break -%} + {%- endif -%} + {%- unless forloop.last -%} + , + {%- endunless -%} + {%- endfor -%} + } {%- unless forloop.last -%} , {%- endunless -%} {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -},"90d":{ - -{%- if site.data[analytics_path].install[analytics_data_source]["90d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install[analytics_data_source]["90d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -},"365d":{ - -{%- if site.data[analytics_path].install[analytics_data_source]["365d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install[analytics_data_source]["365d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -}},"install_on_request":{"30d":{ - -{%- if site.data[analytics_path].install-on-request[analytics_data_source]["30d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install-on-request[analytics_data_source]["30d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -},"90d":{ - -{%- if site.data[analytics_path].install-on-request[analytics_data_source]["90d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install-on-request[analytics_data_source]["90d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -},"365d":{ - -{%- if site.data[analytics_path].install-on-request[analytics_data_source]["365d"].formulae[full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].install-on-request[analytics_data_source]["365d"].formulae[full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -}},"build_error":{"30d":{ - -{%- if site.data[analytics_path].build-error[analytics_data_source]["30d"].formulae[full_full_name].size > 0 -%} - {%- for fa in site.data[analytics_path].build-error[analytics_data_source]["30d"].formulae[full_full_name] -%} - {{ fa.formula | jsonify }}:{{ fa.count | remove: "," | plus: 0 }} - {%- unless forloop.last -%} - , - {%- endunless -%} - {%- endfor -%} -{%- else -%} - {{ full_name | jsonify }}:0 -{%- endif -%} -}}},"generated_date":"{{ "today" | date: "%F" }}"} + }, +{%- endfor -%} +"generated_date":"{{ "today" | date: "%F" }}"}