From 4cf2ecb18aebd7f46eb0e2af375e9d0ecd82bb9e Mon Sep 17 00:00:00 2001
From: Georg Krause <mail@georg-krause.net>
Date: Mon, 6 Mar 2023 18:26:32 +0100
Subject: [PATCH] feat: Add donation page

---
 budget.csv                       | 14 +++++
 pelicanconf.py                   | 27 ++++++++-
 theme/templates/donate.html.j2   | 99 ++++++++++++++++++++++++++++++++
 theme/templates/inc/menu.html.j2 |  2 +-
 4 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 budget.csv
 create mode 100644 theme/templates/donate.html.j2

diff --git a/budget.csv b/budget.csv
new file mode 100644
index 00000000..bb0fceb9
--- /dev/null
+++ b/budget.csv
@@ -0,0 +1,14 @@
+FUNKWHALE | BUDGET OVERVIEW,,,,,
+,,,,,
+,PLAN BALANCE,PLAN 2023,ACT BALANCE,ACTUAL 2023,ACTUAL 2022
+IN,,,,,
+Donations,"13626,51",965,"12835,63","174,12","12661,51"
+Grants,0,0,0,0,0
+OUT,,,,,
+CCT 10%,"-1362,651","-96,5","-1283,563","-17,412","-1266,151"
+Salary,-3900,-3900,0,0,0
+Development,0,0,0,0,0
+Hosting,"-1601,4365",-1140,"-555,2465","-93,81","-461,4365"
+Travel,0,0,0,0,0
+Other,0,0,0,0,0
+BALANCE TOTAL,"6762,4225","-4171,5","10996,8205","62,898","10933,9225"
diff --git a/pelicanconf.py b/pelicanconf.py
index 01cfc031..91dc9ff2 100644
--- a/pelicanconf.py
+++ b/pelicanconf.py
@@ -1,6 +1,6 @@
 AUTHOR = "Funkwhale Collective"
 SITENAME = "Funkwhale"
-SITEURL = ""
+SITEURL = "http://localhost:8161"
 
 PATH = "content"
 OUTPUT_PATH = "public/"
@@ -46,7 +46,7 @@ PAGE_LANG_URL = "{slug}"
 # use the english one as fallback if there is no translated version for a
 # language
 PAGE_LANG_SAVE_AS = "{slug}/{lang}.html"
-PAGE_URL = "{slug}"
+PAGE_URL = "{slug}.html"
 PAGE_SAVE_AS = "{slug}/index.html"
 
 PLUGIN_PATHS = ["pelican-plugins"]
@@ -92,6 +92,27 @@ LAST_RELEASE = data["releases"][0]["id"]
 # ).entries
 BLOG_ARTICLES = []
 
+import csv
+import os
+from datetime import datetime
+
+BUDGET = []
+
+BUDGET_TIME = datetime.fromtimestamp(os.stat("budget.csv").st_mtime)
+
+with open("budget.csv") as budget:
+    next(budget)
+    next(budget)
+    # fieldnames = ["title", "sum", "2023", "2022"]
+    reader = csv.DictReader(budget)  # , fieldnames=fieldnames)
+    reader.fieldnames[0] = "title"
+    reader.fieldnames[3] = "balance"
+
+    for row in reader:
+        if row["title"] in ["IN", "OUT"]:
+            continue
+        BUDGET.append(row)
+
 DIRECT_TEMPLATES = [
     # defaults
     "index",
@@ -106,6 +127,8 @@ DIRECT_TEMPLATES = [
     "contact",
     "credits",
     "apps",
+    "donate",
 ]
 
 TEMPLATE_EXTENSIONS = [".html.j2", ".html"]
+PORT = 8161
diff --git a/theme/templates/donate.html.j2 b/theme/templates/donate.html.j2
new file mode 100644
index 00000000..7f496762
--- /dev/null
+++ b/theme/templates/donate.html.j2
@@ -0,0 +1,99 @@
+{% extends "base.html.j2" %}
+{% block content %}
+  <section class="hero">
+    <style scoped>
+      .hero {
+          padding-top: 50px;
+          background-color: var(--fw-beige-100);
+          text-align: center;
+      }
+
+      .side-by-side {
+          display: flex;
+          gap: 100px;
+          max-width: 800px;
+          margin: 50px auto;
+          align-items: center;
+      }
+
+      .side-by-side .text {
+          max-width: 320px;
+      }
+
+      i.card-image {
+          font-size: 160px;
+      }
+
+      .reports {
+          max-width: 800px;
+          margin: auto;
+          margin-bottom: 75px;
+      }
+
+      table {
+          width: 100%;
+          table-layout: fixed;
+      }
+
+      table tr:nth-child(even) {
+          background-color: #f2f2f2;
+      }
+
+      table tr:hover {
+          background-color: #ddd;
+      }
+
+      table .number {
+          text-align: end;
+      }
+
+      p.updated {
+          font-size: small;
+          margin-top: 5px;
+      }
+    </style>
+    <h1>Donate to Funkwhale</h1>
+    <div class="side-by-side">
+      <div class="text">
+        <p>
+          We're a team of volunteers, commited to develop, maintain and enhance Funkwhale. To do that, though, we need your help, and this includes your financial support.
+        </p>
+      </div>
+      <div class="funkwhale card has-image">
+        <i class="fa fa-open-collective card-image" aria-hidden="true"></i>
+        <div class="card-button">
+          <a class="funkwhale button is-colored is-primary"
+             href="https://opencollective.com/funkwhale/contribute">Donate via OpenCollective</a>
+        </div>
+      </div>
+    </div>
+    <p>
+      We're also relying on lot on <a href="{{ SITEURL }}/credits">third party services and projects</a> who may benefit from your help.
+    </p>
+    <p>Supporting those projects will have an positive impact on Funkwhale, too!</p>
+  </section>
+  <section class="reports">
+    <h2>How we use the money</h2>
+    <p>You'll fine a detailed budget for our expenses and revenue below.</p>
+    <p>
+      Please note that we are looking for ways to pay our contributors for their work, and the positive balance doesn't mean we aren't needing additional support ;)
+    </p>
+    <table>
+      <tr>
+        <th></th>
+        <th>Balance</th>
+        <th>2023</th>
+        <th>2022</th>
+      </tr>
+      {% for row in BUDGET %}
+        <tr>
+          <td>{{ row.title }}</td>
+          <td class="number">{{ row["balance"] | replace(",", ".") | float | round(2) }} €</td>
+          <td class="number">{{ row["ACTUAL 2023"] | replace(",", ".") | float | round(2) }} €</td>
+          <td class="number">{{ row["ACTUAL 2022"] | replace(",", ".") | float | round(2) }} €</td>
+        </tr>
+      {% endfor %}
+    </table>
+    <p class="updated">Last updated {{ BUDGET_TIME }}</p>
+  </section>
+{% endblock content %}
diff --git a/theme/templates/inc/menu.html.j2 b/theme/templates/inc/menu.html.j2
index 4e3fb8fb..5a108fc9 100644
--- a/theme/templates/inc/menu.html.j2
+++ b/theme/templates/inc/menu.html.j2
@@ -91,7 +91,7 @@
       <a href="{{ SITEURL }}/contribute" class="navbar-item">Contribute</a>
     </li>
     <li>
-      <a href="{{ SITEURL }}/support-us" class="navbar-item">Support us</a>
+      <a href="{{ SITEURL }}/donate" class="navbar-item">Support us</a>
     </li>
     <li>
       <a href="{{ SITEURL }}#get-started"
-- 
GitLab