From abd425c62877163cb32a9c43bc770de0195c9375 Mon Sep 17 00:00:00 2001 From: Philippe Loctaux
Date: Sun, 20 Jul 2025 21:38:08 +0200
Subject: [PATCH] use rocket config infrastructure to provide assets + blog
feed, add justfile
---
crates/plcom/justfile | 11 +++++++++++
crates/plcom/src/main.rs | 32 ++++++++++++++++++++++++++++----
crates/plcom/src/pages.rs | 6 +++---
flake.nix | 2 +-
4 files changed, 43 insertions(+), 8 deletions(-)
create mode 100644 crates/plcom/justfile
diff --git a/crates/plcom/justfile b/crates/plcom/justfile
new file mode 100644
index 0000000..79aa44c
--- /dev/null
+++ b/crates/plcom/justfile
@@ -0,0 +1,11 @@
+#!/usr/bin/env just --justfile
+
+# list recipes
+default:
+ just --list
+
+run:
+ PLCOM_ASSETS=../../public PLCOM_BLOG_FEED=/Users/phil/x/blog/target/blog/atom.xml cargo run
+
+tailwind:
+ nix-shell -p tailwindcss_4 --run 'tailwindcss --input ./css/main.css --cwd {{invocation_directory()}}' > ../../public/style.css
diff --git a/crates/plcom/src/main.rs b/crates/plcom/src/main.rs
index 387caa5..d4a76ea 100644
--- a/crates/plcom/src/main.rs
+++ b/crates/plcom/src/main.rs
@@ -14,18 +14,42 @@ mod pages;
mod views;
use pages::*;
+use rocket::fairing::AdHoc;
+
+#[derive(rocket::serde::Deserialize, Debug)]
+#[serde(crate = "rocket::serde")]
+struct Config {
+ assets: String,
+ blog_feed: String,
+}
+
+pub fn config() -> rocket::figment::Figment {
+ use rocket::figment::providers::*;
+ use rocket::figment::Figment;
+ use rocket::Config;
+
+ // rocket defaults
+ Figment::from(Config::default())
+ // from env variables directly
+ .merge(Env::prefixed("PLCOM_").ignore(&["PROFILE"]).global())
+}
#[rocket::launch]
fn rocket() -> _ {
- let assets = std::env::var("PLCOM_ASSETS_PATH").unwrap_or("../../public".into());
+ let rocket = rocket::custom(config());
+ let figment = rocket.figment();
- let server = rocket::build()
- .mount("/", rocket::fs::FileServer::from(assets))
+ let config: Config = figment.extract().expect("server configuration");
+ println!("Using configuration {config:#?}");
+
+ let server = rocket
+ .mount("/", rocket::fs::FileServer::from(config.assets))
.mount(
"/",
rocket::routes![root_route, email_route, wallpapers_route],
)
- .register("/", rocket::catchers![not_found]);
+ .register("/", rocket::catchers![not_found])
+ .attach(AdHoc::config::