Skip to content

Commit

Permalink
fix: json order for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
hteumeuleu committed Jan 28, 2024
1 parent bbfc5be commit 3f20ca6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
45 changes: 45 additions & 0 deletions _js/api-ordered.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: null
permalink: "/api/data-ordered.json"
---
{
"api_version":"1.0.4-ordered",
"last_update_date":{{site.time | jsonify}},
"nicenames":{{site.data.nicenames | jsonify}},
"data":[{% for feature in site.features %}
{
"slug":{{ feature.slug | jsonify }},
"title":{{ feature.title | jsonify }},
"description":{{ feature.description | jsonify }},
"url":{{ feature.url | prepend:site.url | jsonify }},
"category":{{ feature.category | jsonify }},
"tags":{{ feature.tags | jsonify }},
"keywords":{{ feature.keywords | jsonify }},
"last_test_date":{{ feature.last_test_date | jsonify }},
"test_url":{{ feature.test_url | prepend:site.url | jsonify }},
"test_results_url":{{ feature.test_results_url | jsonify }},
"stats":{
{%- for family in feature.stats -%}
{%- assign family-key = family | first -%}
{%- assign family-values = feature.stats[family-key] -%}
{{ family-key | jsonify }}:{
{%- for platform in family-values -%}
{%- assign platform-key = platform | first -%}
{%- assign platform-values = platform | last -%}
{{ platform-key | jsonify }}:[
{%- for version in platform-values -%}
{%- assign version-key = version | first -%}
{%- assign version-values = version | last | split: ' ' | first -%}
{ {{ version-key | jsonify }}:{{ version-values | jsonify }} }
{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
]{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
},
"notes":{{ feature.notes | jsonify}},
"notes_by_num":{{ feature.notes_by_num | jsonify}}
}{% unless forloop.last %},{% endunless %}
{% endfor %}]
}
15 changes: 10 additions & 5 deletions _js/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Compare {
loadJSONFile() {

if(!this.data) {
fetch('/api/data.json')
fetch('/api/data-ordered.json')
.then(response => {
return response.json();
})
Expand Down Expand Up @@ -305,8 +305,10 @@ class Compare {
const versions = feature.stats[key[0]][key[1]];
supportValue = 'u';
if(versions) {
const lastVersionKey = Object.keys(versions)[Object.keys(versions).length - 1];
const lastVersionValue = versions[lastVersionKey];
const lastVersion = versions[versions.length - 1];
const lastVersionKey = Object.keys(lastVersion)[0];
const lastVersionValue = lastVersion[lastVersionKey];
console.log(versions, lastVersionKey, lastVersionValue);
if(lastVersionValue) {
supportValue = lastVersionValue.charAt(0);
}
Expand Down Expand Up @@ -381,9 +383,12 @@ class Compare {
if(key[0] in feature.stats && key[1] in feature.stats[key[0]]) {
const versions = feature.stats[key[0]][key[1]];
if(versions) {
const lastVersionSupportValue = versions[Object.keys(versions)[Object.keys(versions).length - 1]];
// const lastVersionSupportValue = versions[Object.keys(versions)[Object.keys(versions).length - 1]];
const lastVersionSupportValue = versions[versions.length - 1];
if(lastVersionSupportValue) {
const supportValue = lastVersionSupportValue.charAt(0);
const key = Object.keys(lastVersionSupportValue)[0];
const value = lastVersionSupportValue[key];
const supportValue = value.charAt(0);
if(!averageSupportValue) {
averageSupportValue = supportValue;
} else if(averageSupportValue == 'u' && supportValue != 'u') {
Expand Down
2 changes: 1 addition & 1 deletion pages/clients.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ <h1 class="post-title">Email Clients</h1>
</div>
</div>
</div>
<link rel="prefetch" href="/api/data.json" />
<link rel="prefetch" href="/api/data-ordered.json" />
<script src="/assets/js/compare.js" defer></script>

0 comments on commit 3f20ca6

Please sign in to comment.