From 3b83bc89a0ef5f627e532b94441e78a7f00ca84b Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Thu, 9 Oct 2025 19:32:51 +0200 Subject: [PATCH] add stat cards to index page, new pattern, misc --- src/days.rs | 8 +++++ src/discordbot/member_count/mod.rs | 3 +- src/main.rs | 3 ++ src/router/mod.rs | 13 +++----- src/website/pages/index.rs | 22 +++++++++++-- web/index.html | 14 ++++++--- web/input.css | 50 ++++++++++++++++++++++++++++++ web/statcard.html | 8 +++++ 8 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 src/days.rs create mode 100644 web/statcard.html diff --git a/src/days.rs b/src/days.rs new file mode 100644 index 0000000..8eaa5a4 --- /dev/null +++ b/src/days.rs @@ -0,0 +1,8 @@ +use chrono::{NaiveDate, Utc}; + +pub fn days_of_community_existence() -> i64 { + let formation = NaiveDate::from_ymd_opt(2020, 6, 7).unwrap(); + let today = Utc::now().date_naive(); + + today.signed_duration_since(formation).num_days() +} diff --git a/src/discordbot/member_count/mod.rs b/src/discordbot/member_count/mod.rs index c013675..6b1cdf3 100644 --- a/src/discordbot/member_count/mod.rs +++ b/src/discordbot/member_count/mod.rs @@ -12,8 +12,7 @@ pub fn init_service(ctx: &Context, guild_id: &GuildId) { info!("Initialising discord member count service..."); if guild_id != MAIN_GUILD_ID { - info!("Guild member count service not initialised; Bot not running on main guild."); - return; + info!("Guild member count service initialised, but bot not running on main guild."); } tokio::spawn(async move { diff --git a/src/main.rs b/src/main.rs index b03faaf..01f68cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,14 @@ use std::error::Error; use tokio::net::TcpListener; +mod days; mod discordbot; mod router; mod setup; mod website; +const SHRUG: &'static str = "¯\\_(ツ)_/¯"; + #[tokio::main] async fn main() -> Result<(), Box> { setup::dotenv_and_tracing(); diff --git a/src/router/mod.rs b/src/router/mod.rs index b97ad65..9d087cf 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -1,8 +1,9 @@ use axum::{Router, http::StatusCode, routing::get}; -use chrono::{NaiveDate, Utc}; use tower::service_fn; -use crate::{router::redirects::redirects, website::website_service}; +use crate::{ + days::days_of_community_existence, router::redirects::redirects, website::website_service, +}; mod redirects; @@ -28,7 +29,7 @@ async fn api_fallback() -> (StatusCode, String) { async fn get_member_count() -> (StatusCode, String) { match crate::discordbot::get_member_count().await { - Some(count) => (StatusCode::OK, format!("{count}")), + Some(count) => (StatusCode::OK, count.to_string()), None => ( StatusCode::INTERNAL_SERVER_ERROR, format!("An error occured - could not fetch discord member count."), @@ -37,9 +38,5 @@ async fn get_member_count() -> (StatusCode, String) { } async fn get_days_since_community_formation() -> String { - let formation = NaiveDate::from_ymd_opt(2020, 6, 7).unwrap(); - let today = Utc::now().date_naive(); - let days = today.signed_duration_since(formation).num_days(); - - days.to_string() + days_of_community_existence().to_string() } diff --git a/src/website/pages/index.rs b/src/website/pages/index.rs index c5ac866..56c1dc2 100644 --- a/src/website/pages/index.rs +++ b/src/website/pages/index.rs @@ -4,14 +4,30 @@ use axum::{ response::{Html, IntoResponse, Response}, }; -use crate::website::pages::INTERNAL_SERVER_ERROR_MSG; +use crate::{ + SHRUG, days::days_of_community_existence, discordbot::get_member_count, + website::pages::INTERNAL_SERVER_ERROR_MSG, +}; #[derive(Template)] #[template(path = "index.html")] -struct PageIndex; +struct PageIndex { + /// approximate discord server member count + dsc_members: String, + days_community: i64, +} pub async fn page_index() -> Response { - let a = PageIndex; + let a = PageIndex { + dsc_members: match get_member_count().await { + Some(count) => match count { + ..=512 => format!("{count}"), + _ => format!("~{count}"), + }, + None => SHRUG.into(), + }, + days_community: days_of_community_existence(), + }; match a.render() { Ok(res) => (StatusCode::OK, Html(res)).into_response(), Err(_e) => (StatusCode::INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MSG).into_response(), diff --git a/web/index.html b/web/index.html index 4bffb36..4904495 100644 --- a/web/index.html +++ b/web/index.html @@ -1,10 +1,11 @@ {% extends "base.html" %} {# # # # # # # # # # # # # # # # # # # # # # # # # #} +{%- import "statcard.html" as statcard -%} {# # # # # # # # # # # # # # # # # #} {% block title %}gractwo.pl | Witamy!{% endblock %} {% block pagecontent %}
-
+
{% include "gractwo.svg" %}

+
+ {%call statcard::statcard(dsc_members, "członków na discordzie")%} + {%call statcard::statcard(days_community, "dni istnienia + społeczności")%} + +
-{% include "footer.html" %} {# # # # # # # # # # # # # # # # # # # # # # # # #} -{% endblock %} +{% include "footer.html" %} {% endblock %} diff --git a/web/input.css b/web/input.css index 290dbae..49cf9f2 100644 --- a/web/input.css +++ b/web/input.css @@ -16,6 +16,56 @@ linear-gradient(to right, #ff637e 15%, #00d3f2 100%); } +.dashed-top-fade-grid { + position: absolute; + inset: 0; + z-index: 0; + + background-image: + linear-gradient(to right, #e7e5e4 1px, transparent 1px), + linear-gradient(to bottom, #e7e5e4 1px, transparent 1px); + background-size: 20px 20px; + background-position: + 0 0, + 0 0; + + mask-image: + repeating-linear-gradient( + to right, + black 0px, + black 3px, + transparent 3px, + transparent 8px + ), + repeating-linear-gradient( + to bottom, + black 0px, + black 3px, + transparent 3px, + transparent 8px + ), + radial-gradient(ellipse 70% 60% at 50% 0%, #000 60%, transparent 100%); + -webkit-mask-image: + repeating-linear-gradient( + to right, + black 0px, + black 3px, + transparent 3px, + transparent 8px + ), + repeating-linear-gradient( + to bottom, + black 0px, + black 3px, + transparent 3px, + transparent 8px + ), + radial-gradient(ellipse 70% 60% at 50% 0%, #000 60%, transparent 100%); + + mask-composite: intersect; + -webkit-mask-composite: source-in; +} + .dashed-bottom-fade-grid { position: absolute; inset: 0; diff --git a/web/statcard.html b/web/statcard.html new file mode 100644 index 0000000..0449e38 --- /dev/null +++ b/web/statcard.html @@ -0,0 +1,8 @@ +{% macro statcard(number, description) %} +
+

{{ number }}

+

{{ description }}

+
+{% endmacro %}