Files
static-pages/donate.sh
T
naomi 43a021d802
Code Analysis / SonarQube (push) Failing after 15s
fix: couple of bugs
2025-09-23 13:21:27 -07:00

91 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"
DONATE_JSON_URL="https://data.nhcarrigan.com/donate.json"
DONATE_JSON_FILE="donate.json"
DONATE_HTML_FILE="donate/index.html"
# Templating
HTML_START='<!DOCTYPE html>
<html lang="en">
<head>
<title>Donate</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="Support our work and help us make a difference!"
/>
<script
src="https://cdn.nhcarrigan.com/headers/index.js"
async
defer
></script>
<style>
.badge {
width: 80%;
margin: auto;
border-radius: 5550px;
padding: 10px;
}
.url {
display: grid;
grid-template-columns: 100px auto;
align-items: center;
color: unset;
text-decoration: none;
}
i {
font-size: 3rem;
}
.name {
font-size: 1.2rem;
}
.text {
text-align: center;
}
</style>
</head>
<body>
<main>
<h1>Donate</h1>
<p>Support our work and help us make a difference!</p>
<section>
'
HTML_END=' </section>
</main>
</body>
</html>
'
# Fetch the latest donate.json
curl -sSL "$DONATE_JSON_URL" -o "$DONATE_JSON_FILE"
# Convert JSON to HTML, sorted by date descending (newest first)
DONATE_HTML=$(jq -r '.[] |
"<div class=\"badge\" style=\"color: " + .foreground + "; background: " + .background + "\">
<a href=\"" + .url + "\" class=\"url\">
<i class=\"" + .icon + "\"></i>
<div class=\"text\">
<p class=\"name\">" + .name + "</p>
<p class=\"description\">" + .description + "</p>
</div>
</a>
</div>"
' "$DONATE_JSON_FILE")
# Create temporary file with the HTML content
echo "$HTML_START" > "$DONATE_HTML_FILE"
echo "$DONATE_HTML" >> "$DONATE_HTML_FILE"
echo "$HTML_END" >> "$DONATE_HTML_FILE"
echo "Donate updated in $DONATE_HTML_FILE"
# Clean up
rm "$DONATE_JSON_FILE"