My personal site cherry.computer
htmx tailwind axum askama

feat: randomly change the verb for media consumption on refresh

cherry.computer 66cf1117 e71c9acc

verified
+57 -4
+41 -2
server/Cargo.lock
··· 1174 "axum", 1175 "cached", 1176 "jsonwebtoken", 1177 "reqwest", 1178 "scraper", 1179 "serde", ··· 1382 checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" 1383 dependencies = [ 1384 "phf_shared", 1385 - "rand", 1386 ] 1387 1388 [[package]] ··· 1441 checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" 1442 1443 [[package]] 1444 name = "precomputed-hash" 1445 version = "0.1.1" 1446 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1476 source = "registry+https://github.com/rust-lang/crates.io-index" 1477 checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 1478 dependencies = [ 1479 - "rand_core", 1480 ] 1481 1482 [[package]] ··· 1484 version = "0.6.4" 1485 source = "registry+https://github.com/rust-lang/crates.io-index" 1486 checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 1487 1488 [[package]] 1489 name = "redox_syscall"
··· 1174 "axum", 1175 "cached", 1176 "jsonwebtoken", 1177 + "rand 0.9.2", 1178 "reqwest", 1179 "scraper", 1180 "serde", ··· 1383 checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" 1384 dependencies = [ 1385 "phf_shared", 1386 + "rand 0.8.5", 1387 ] 1388 1389 [[package]] ··· 1442 checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" 1443 1444 [[package]] 1445 + name = "ppv-lite86" 1446 + version = "0.2.21" 1447 + source = "registry+https://github.com/rust-lang/crates.io-index" 1448 + checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" 1449 + dependencies = [ 1450 + "zerocopy", 1451 + ] 1452 + 1453 + [[package]] 1454 name = "precomputed-hash" 1455 version = "0.1.1" 1456 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1486 source = "registry+https://github.com/rust-lang/crates.io-index" 1487 checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 1488 dependencies = [ 1489 + "rand_core 0.6.4", 1490 + ] 1491 + 1492 + [[package]] 1493 + name = "rand" 1494 + version = "0.9.2" 1495 + source = "registry+https://github.com/rust-lang/crates.io-index" 1496 + checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" 1497 + dependencies = [ 1498 + "rand_chacha", 1499 + "rand_core 0.9.3", 1500 + ] 1501 + 1502 + [[package]] 1503 + name = "rand_chacha" 1504 + version = "0.9.0" 1505 + source = "registry+https://github.com/rust-lang/crates.io-index" 1506 + checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" 1507 + dependencies = [ 1508 + "ppv-lite86", 1509 + "rand_core 0.9.3", 1510 ] 1511 1512 [[package]] ··· 1514 version = "0.6.4" 1515 source = "registry+https://github.com/rust-lang/crates.io-index" 1516 checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 1517 + 1518 + [[package]] 1519 + name = "rand_core" 1520 + version = "0.9.3" 1521 + source = "registry+https://github.com/rust-lang/crates.io-index" 1522 + checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" 1523 + dependencies = [ 1524 + "getrandom 0.3.3", 1525 + ] 1526 1527 [[package]] 1528 name = "redox_syscall"
+1
server/Cargo.toml
··· 12 axum = "0.8.1" 13 cached = { version = "0.56.0", features = ["async"] } 14 jsonwebtoken = "9.3.1" 15 reqwest = { version = "0.12.23", features = ["json"] } 16 scraper = "0.24.0" 17 serde = { version = "1.0.219", features = ["derive"] }
··· 12 axum = "0.8.1" 13 cached = { version = "0.56.0", features = ["async"] } 14 jsonwebtoken = "9.3.1" 15 + rand = "0.9.2" 16 reqwest = { version = "0.12.23", features = ["json"] } 17 scraper = "0.24.0" 18 serde = { version = "1.0.219", features = ["derive"] }
+14 -1
server/src/index.rs
··· 5 }; 6 7 use askama::Template; 8 use serde::Deserialize; 9 10 #[derive(Deserialize)] ··· 18 #[template(path = "index.html")] 19 pub struct RootTemplate { 20 media: Vec<Media>, 21 } 22 23 impl RootTemplate { ··· 34 #[cfg(not(debug_assertions))] 35 let media = Self::fetch_media(apple_music_client).await; 36 37 - RootTemplate { media } 38 } 39 40 async fn fetch_media(apple_music_client: &AppleMusicClient) -> Vec<Media> { ··· 44 apple_music::cached_fetch(apple_music_client) 45 ); 46 [game, movie, song].into_iter().flatten().collect() 47 } 48 } 49
··· 5 }; 6 7 use askama::Template; 8 + use rand::seq::IndexedRandom; 9 use serde::Deserialize; 10 11 #[derive(Deserialize)] ··· 19 #[template(path = "index.html")] 20 pub struct RootTemplate { 21 media: Vec<Media>, 22 + consumption_verb: &'static str, 23 } 24 25 impl RootTemplate { ··· 36 #[cfg(not(debug_assertions))] 37 let media = Self::fetch_media(apple_music_client).await; 38 39 + let consumption_verb = Self::random_consumption_verb(); 40 + 41 + RootTemplate { 42 + media, 43 + consumption_verb, 44 + } 45 } 46 47 async fn fetch_media(apple_music_client: &AppleMusicClient) -> Vec<Media> { ··· 51 apple_music::cached_fetch(apple_music_client) 52 ); 53 [game, movie, song].into_iter().flatten().collect() 54 + } 55 + 56 + fn random_consumption_verb() -> &'static str { 57 + static CONSUMPTION_VERBS: &[&str] = &["swallowed", "inhaled", "digested", "ingested"]; 58 + 59 + CONSUMPTION_VERBS.choose(&mut rand::rng()).unwrap() 60 } 61 } 62
+1 -1
server/templates/index.html
··· 31 </div> 32 {% if media.len() > 0 -%} 33 <h2 class="self-start text-3xl text-pink-50"> 34 - Here is what I've swallowed most recently: 35 </h2> 36 <div class="grid grid-cols-{{ media.len() }}"> 37 {% for media in media -%}
··· 31 </div> 32 {% if media.len() > 0 -%} 33 <h2 class="self-start text-3xl text-pink-50"> 34 + Here is what I've {{ consumption_verb }} most recently: 35 </h2> 36 <div class="grid grid-cols-{{ media.len() }}"> 37 {% for media in media -%}