Skip to content

Commit

Permalink
formula_json: compress markup into for loops, add analytics-linux
Browse files Browse the repository at this point in the history
and fix "full_full_name" typo
  • Loading branch information
EricFromCanada committed Oct 31, 2021
1 parent 0a08d3c commit 197b3ec
Showing 1 changed file with 33 additions and 91 deletions.
124 changes: 33 additions & 91 deletions _layouts/formula_json.json
Original file line number Diff line number Diff line change
@@ -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" }}"}

0 comments on commit 197b3ec

Please sign in to comment.