Skip to content

Commit 301368a

Browse files
committed
Add basic donation statistics to the website
1 parent 34dced3 commit 301368a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

website/content/donate.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Donate"
33

44
[extra]
5-
css = ["/page/donate.css", "/component/feature-box.css"]
5+
css = ["/page/donate.css", "/component/feature-box.css", "/component/feature-icons.css"]
66
+++
77

88
<section>
@@ -26,6 +26,45 @@ css = ["/page/donate.css", "/component/feature-box.css"]
2626

2727
</p>
2828

29+
<div class="feature-icons four-wide statistics" data-statistics>
30+
<div class="feature-icon">
31+
<img class="atlas" style="--atlas-index: 34" src="https://static.graphite.rs/icons/icon-atlas-roadmap__3.png" alt="" />
32+
<span data-statistics-dollars></span>
33+
</div>
34+
<div class="feature-icon">
35+
<img class="atlas" style="--atlas-index: 3" src="https://static.graphite.rs/icons/icon-atlas-features__2.png" alt="" />
36+
<span data-statistics-members></span>
37+
</div>
38+
<div class="feature-icon">
39+
<img class="atlas" style="--atlas-index: 47" src="https://static.graphite.rs/icons/icon-atlas-roadmap__3.png" alt="" />
40+
<span data-statistics-donors></span>
41+
</div>
42+
</div>
43+
44+
<script>
45+
(async () => {
46+
const element = document.querySelector("[data-statistics]");
47+
const dollarsElement = document.querySelector("[data-statistics-dollars]");
48+
const membersElement = document.querySelector("[data-statistics-members]");
49+
const donorsElement = document.querySelector("[data-statistics-donors]");
50+
if (!dollarsElement || !membersElement || !donorsElement) return;
51+
try {
52+
const response = await fetch("https://graphite.rs/sponsorship-stats");
53+
const json = await response.json();
54+
if (!json || !json.recurring || !json.one_time_prior_3_month_sum) throw new Error();
55+
const recurringDollars = parseInt(json.recurring.cents) / 100;
56+
const oneTimeAverageDollars = parseInt(json.one_time_prior_3_month_sum.cents) / 100 / 3;
57+
dollarsElement.innerText = "$" + Math.round(recurringDollars + oneTimeAverageDollars).toLocaleString("en-US") + " / month";
58+
membersElement.innerText = json.recurring.count.toLocaleString("en-US") + " members (supporting monthly)";
59+
donorsElement.innerText = Math.round(json.one_time_prior_3_month_sum.count / 3).toLocaleString("en-US") + " one-time donors (past month)";
60+
// Force repaint to work around Safari bug <https://bugs.webkit.org/show_bug.cgi?id=286403> (remove this and its data attribute when the bug is fixed and widely deployed)
61+
element.style.transform = "scale(1)";
62+
} catch {
63+
element.remove();
64+
}
65+
})();
66+
</script>
67+
2968
Graphite is 100% built and funded by the community. Your contributions directly help us level up the scope and speed of the project's development. Resources are put towards infrastructure, operational costs, swag to keep contributors happy and motivated, and outreach like exhibiting at conventions and traveling to conferences to foster industry relationships. Hiring full-time developers is the next crucial milestone.
3069

3170
</div>

website/sass/page/donate.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
}
2222
}
2323

24+
.statistics:has(span:empty) {
25+
visibility: hidden;
26+
}
27+
2428
#supporter-memberships,
2529
#corporate-sponsorships {
2630
.triptych {

0 commit comments

Comments
 (0)