diff options
| author | 2026-01-02 01:23:45 +0100 | |
|---|---|---|
| committer | 2026-01-02 01:23:45 +0100 | |
| commit | 0644a094bf0a9ef3a11661a32f339010bcf17c55 (patch) | |
| tree | edaf56912de5b89b9102cf2b213db21687ad8bf4 | |
| parent | e77949acd6c62f698727f84d03d5f3aacba1004c (diff) | |
| download | blossom-0644a094bf0a9ef3a11661a32f339010bcf17c55.tar.gz blossom-0644a094bf0a9ef3a11661a32f339010bcf17c55.tar.bz2 blossom-0644a094bf0a9ef3a11661a32f339010bcf17c55.zip | |
Diffstat (limited to '')
| -rw-r--r-- | TODO.md | 4 | ||||
| -rw-r--r-- | resources/en/base.ftl | 1 | ||||
| -rw-r--r-- | src/main.rs | 12 | ||||
| -rw-r--r-- | src/templates.rs | 1 | ||||
| -rw-r--r-- | src/visits.rs | 14 | ||||
| -rw-r--r-- | templates/home.html | 7 |
6 files changed, 35 insertions, 4 deletions
@@ -12,7 +12,7 @@ [x] update serving https badges better thumb LOL [ ] migrate to ructe [ ] opengraph -[ ] publish new poetry +[x] publish new poetry [x] make sure posts are organised in date order [x] atom feed [x] tags @@ -40,7 +40,7 @@ [ ] comments [ ] brush font PLZ [ ] deploy database yum -[ ] visitor counter +[x] visitor counter [ ] guestbook [ ] webmention [x] h-card diff --git a/resources/en/base.ftl b/resources/en/base.ftl index 7c58882..aef187d 100644 --- a/resources/en/base.ftl +++ b/resources/en/base.ftl @@ -8,3 +8,4 @@ filter-by-tags = Filter by Tags permalink = Permalink untitled = Untitled now-playing = Now Playing +visits = {" "}visits diff --git a/src/main.rs b/src/main.rs index 7247c33..bbfcbff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod scrobbles; mod skweets; mod templates; mod utils; +mod visits; use std::{collections::HashSet, time::Duration}; @@ -54,17 +55,23 @@ struct Static; #[handler] async fn home(Data(reqwest): Data<&reqwest::Client>, locale: Locale) -> templates::Home { let listenbrainz_client = listenbrainz::raw::Client::new(); - let (live, listenbrainz, blogposts, poems) = tokio::join!( + let (live, listenbrainz, blogposts, poems, visits) = tokio::join!( live::get_live_status(reqwest), scrobbles::get_now_playing(&listenbrainz_client), // skweets::get_recents(&clients.skinnyverse), Blogpost::get_articles(), - Poem::get_articles() + Poem::get_articles(), + visits::get_visits(reqwest) ); let is_live = live.unwrap_or_default().online; let listenbrainz = listenbrainz.unwrap_or_default(); let blogposts = blogposts.unwrap_or_default(); let poems = poems.unwrap_or_default(); + // let visits = visits.ok().map(|v| v.count); + let visits = visits + .ok() + .map(|v| v.count.replace("\u{202f}", "")) + .and_then(|c| c.parse().ok()); let mut posts = blogposts .iter() @@ -96,6 +103,7 @@ async fn home(Data(reqwest): Data<&reqwest::Client>, locale: Locale) -> template locale, filter_tags: HashSet::new(), jiggle: 8, + visits, } } diff --git a/src/templates.rs b/src/templates.rs index c086487..c0b3c14 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -29,6 +29,7 @@ pub struct Home { pub locale: Locale, pub filter_tags: HashSet<String>, pub jiggle: isize, + pub visits: Option<usize>, } #[derive(Template)] diff --git a/src/visits.rs b/src/visits.rs new file mode 100644 index 0000000..1e0685c --- /dev/null +++ b/src/visits.rs @@ -0,0 +1,14 @@ +use reqwest::Client; +use serde::Deserialize; + +use crate::Result; + +#[derive(Deserialize, Default)] +pub struct Visits { + pub count: String, +} + +pub async fn get_visits(client: &Client) -> Result<Visits> { + let endpoint = "https://stats.blos.sm/counter/TOTAL.json"; + Ok(client.get(endpoint).send().await?.json::<Visits>().await?) +} diff --git a/templates/home.html b/templates/home.html index 95e614c..ba6615f 100644 --- a/templates/home.html +++ b/templates/home.html @@ -50,6 +50,13 @@ {% include "latestposts.html" %} {% include "random-poem.html" %} + {% match visits %} + {% when Some(visit_count) %} + <div class="panel" + style="color: #e9cdcf; background-color: #b52f6a; z-index: -1; font-size: 2em; width: fit-content;"> + {{ visit_count }}{{ locale.text("visits").unwrap() }}</div> + {% when None %} + {% endmatch %} </aside> |
