summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Letan <lthms@soap.coffee>2023-05-18 19:21:49 +0200
committerThomas Letan <lthms@soap.coffee>2023-05-18 19:21:49 +0200
commit77fd9920f8e617a23557d0e0c844bd0812920b44 (patch)
treea8a5b170e32a4d2e951190f88aa04db3849bae61
parentAdd a clean rule to make (diff)
Add the running plugin
-rw-r--r--plugins/running.lua63
-rw-r--r--soupault.toml3
2 files changed, 66 insertions, 0 deletions
diff --git a/plugins/running.lua b/plugins/running.lua
new file mode 100644
index 0000000..26ac6bc
--- /dev/null
+++ b/plugins/running.lua
@@ -0,0 +1,63 @@
+function hsl(h, s, l)
+ return 'hsl(' .. JSON.to_string(h) .. ', ' .. JSON.to_string(s) .. '%, ' .. JSON.to_string(l) .. '%)'
+end
+
+function kilometer(date, n, run)
+ local max_hue = 360
+ local nb_colors = 17
+
+ local hue = (n * nb_colors) % max_hue
+ local bg = hsl(hue, 40, 50 + 10 * (n % 3))
+ local border = hsl(hue, 40, 15)
+
+ return HTML.parse ('<span title="' .. date .. '" class="kilometer '
+ .. run .. '" style="border: 1px solid '
+ .. border .. '; background: ' .. bg .. '"></span>')
+end
+
+containers = HTML.select(page, ".running-container")
+
+index, container = next(containers)
+
+-- This way, we won’t have twice the same page.
+n = Sys.random(100)
+
+while index do
+ if container then
+ total_count = 0
+ stats = YAML.from_string(String.trim(HTML.inner_html(container)))
+ HTML.replace_content(container, HTML.parse(''))
+
+ i = 1
+ while stats[i] do
+ max = stats[i]['count']
+ date = stats[i]['date']
+ race = stats[i]['race']
+
+ total_count = total_count + max
+
+ if not border then
+ border = 'silver'
+ end
+
+ if race then
+ race = "race"
+ else
+ race = ''
+ end
+
+ j = 1
+ while j <= max do
+ HTML.append_child(container, kilometer(date, n, race))
+ j = j + 1
+ end
+
+ i = i + 1
+ n = n + 1
+ end
+
+ HTML.append_child(container, HTML.parse('<p>' .. total_count .. 'km in total.'))
+ end
+
+ index, container = next(containers, index)
+end
diff --git a/soupault.toml b/soupault.toml
index f34810c..d536d4e 100644
--- a/soupault.toml
+++ b/soupault.toml
@@ -69,6 +69,9 @@
[widgets.move-tags]
widget = "move-tags"
+[widgets.running]
+ widget = "running"
+
[index]
index = true
index_first = true