Skip to content

Commit

Permalink
Obtain some of the facts metadata from the data files information
Browse files Browse the repository at this point in the history
  • Loading branch information
andreslucena committed Dec 16, 2024
1 parent 2f7fbd9 commit 79046e6
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 20 deletions.
2 changes: 2 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
require "lib/format_helpers"
require "lib/icon_helpers"
require "lib/page_helpers"
require "lib/facts_helpers"

helpers I18nHelpers
helpers I18nTitleHelpers
helpers DataHelpers
helpers FormatHelpers
helpers IconHelpers
helpers PageHelpers
helpers FactsHelpers

# Activate multi-language
activate :i18n, mount_at_root: :en, langs: [:en, :es, :ca, :cs, :fr, :de, :ja, :"pt-BR", :ro, :fi]
Expand Down
247 changes: 247 additions & 0 deletions data/countries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
- ac
- ad
- ae
- af
- ag
- ai
- al
- am
- ao
- aq
- ar
- as
- at
- au
- aw
- ax
- az
- ba
- bb
- bd
- be
- bf
- bg
- bh
- bi
- bj
- bm
- bn
- bo
- bq
- br
- bs
- bt
- bw
- by
- bz
- ca
- cc
- cd
- cf
- cg
- ch
- ci
- ck
- cl
- cm
- cn
- co
- cr
- cu
- cv
- cw
- cx
- cy
- cz
- de
- dj
- dk
- dm
- do
- dz
- ec
- ee
- eg
- eh
- er
- es
- et
- eu
- fi
- fj
- fk
- fm
- fo
- fr
- ga
- gd
- ge
- gf
- gg
- gh
- gi
- gl
- gm
- gn
- gp
- gq
- gr
- gs
- gt
- gu
- gw
- gy
- hk
- hm
- hn
- hr
- ht
- hu
- id
- ie
- il
- im
- in
- io
- iq
- ir
- is
- it
- je
- jm
- jo
- jp
- ke
- kg
- kh
- ki
- km
- kn
- kp
- kr
- kw
- ky
- kz
- la
- lb
- lc
- li
- lk
- lr
- ls
- lt
- lu
- lv
- ly
- ma
- mc
- md
- me
- mg
- mh
- mk
- ml
- mm
- mn
- mo
- mp
- mq
- mr
- ms
- mt
- mu
- mv
- mw
- mx
- my
- mz
- na
- nc
- ne
- nf
- ng
- ni
- nl
- no
- np
- nr
- nu
- nz
- om
- pa
- pe
- pf
- pg
- ph
- pk
- pl
- pm
- pn
- pr
- ps
- pt
- pw
- py
- qa
- re
- ro
- rs
- ru
- rw
- sa
- sb
- sc
- sd
- se
- sg
- sh
- si
- sk
- sl
- sm
- sn
- so
- sr
- ss
- st
- su
- sv
- sx
- sy
- sz
- tc
- td
- tf
- tg
- th
- tj
- tk
- tl
- tm
- tn
- to
- tr
- tt
- tv
- tw
- tz
- ua
- ug
- uk
- us
- uy
- uz
- va
- vc
- ve
- vg
- vi
- vn
- vu
- wf
- ws
- ye
- yt
- za
- zm
- zw
18 changes: 9 additions & 9 deletions data/facts.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
- value: 390
text: f1
text: instances
- value: 30
text: f2
text: countries
- value: 240
text: f3
text: institutions
- value: 150
text: f4
text: organizations
- value: "925.152"
text: f5
text: participants
- value: 427
text: f6
text: processes
- value: "100.129"
text: f7
text: proposals
- value: "120.554"
text: f8
text: comments
- value: "11.215"
text: f9
text: meetings
44 changes: 44 additions & 0 deletions lib/facts_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require "addressable/uri"

module FactsHelpers
# Get the statistic for this fact type
# If the fact type is not supported, then return the hard-coded figure given as a parameter
#
# @param data_type [String] - The name of the data type. For instance "instances"
# @param fallback [Integer|String] - The number with the hard-coded value in case this type isn't supported
# @param data [Middleman::CoreExtensions::Data::DataStore] - The data object from Middleman, to gather some of the information
def get_statistic_for_fact(data_type, fallback, data)
case data_type
when "instances"
data.installations.count
when "organizations"
data.installations.select {|name, installation| installation["type"] == "org" }.count
when "institutions"
data.installations.select {|name, installation| ["region", "city"].include? installation["type"] }.count
when "countries"
get_countries_from(data)
else
fallback
end
end

private

def get_countries_from(data)
ctlds = data.installations
.map {|name, installation| installation["url"] }
.map { |url| url.gsub(%r{https://web.archive.org/web/\d*/}, "") }
.map { |url| Addressable::URI.parse(url).tld }
.map { |url| url.split(".")[-1] } # Seems like we're getting some garbage, like "milano.it", so this worksaround it
.uniq

counter = 0
ctlds.each do |ctld|
counter+=1 if data.countries.include?(ctld)
end

counter
end
end
19 changes: 10 additions & 9 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,16 @@ en:
cta: Get started
disclaimer: Logos are the intellectual property of their respective copyright holders.<br>They do not fall under the Creative Commons By-SA license the rest of the site's contents are licensed with.
facts:
f1: instances
f2: countries
f3: institutions
f4: organizations
f5: participants
f6: processes
f7: proposals
f8: comments
f9: meetings
type:
instances: instances
countries: countries
institutions: institutions
organizations: organizations
participants: participants
processes: processes
proposals: proposals
comments: comments
meetings: meetings
subtitle: Decidim keeps growing and being adopted by organizations and the community.
title: Facts & Figures
filters:
Expand Down
4 changes: 2 additions & 2 deletions source/partials/_facts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="grid md:grid-cols-3 gap-x-7 md:gap-y-24">
<% data.facts.each_with_index do |use, ix| %>
<div class="md:space-y-3 opacity-0 md:opacity-100 animate-slide-y md:animate-none" style="--translate-ix: <%= ix %>;">
<h2 class="h2"><%= use.value %></h2>
<h6 class="h6"><%= t("used_by.facts.#{use.text}") %></h6>
<h2 class="h2"><%= get_statistic_for_fact(use.text, use.value, data) %></h2>
<h6 class="h6"><%= t("used_by.facts.type.#{use.text}") %></h6>
</div>
<% end %>
</div>
Expand Down
Loading

0 comments on commit 79046e6

Please sign in to comment.