use rocket config infrastructure to provide assets + blog feed, add justfile
This commit is contained in:
parent
0f7165d24b
commit
abd425c628
4 changed files with 43 additions and 8 deletions
11
crates/plcom/justfile
Normal file
11
crates/plcom/justfile
Normal file
|
|
@ -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
|
||||||
|
|
@ -14,18 +14,42 @@ mod pages;
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
use pages::*;
|
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]
|
#[rocket::launch]
|
||||||
fn rocket() -> _ {
|
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()
|
let config: Config = figment.extract().expect("server configuration");
|
||||||
.mount("/", rocket::fs::FileServer::from(assets))
|
println!("Using configuration {config:#?}");
|
||||||
|
|
||||||
|
let server = rocket
|
||||||
|
.mount("/", rocket::fs::FileServer::from(config.assets))
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
rocket::routes![root_route, email_route, wallpapers_route],
|
rocket::routes![root_route, email_route, wallpapers_route],
|
||||||
)
|
)
|
||||||
.register("/", rocket::catchers![not_found]);
|
.register("/", rocket::catchers![not_found])
|
||||||
|
.attach(AdHoc::config::<Config>());
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
server
|
server
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ mod wallpapers;
|
||||||
|
|
||||||
use crate::common::wallpapers::Wallpaper;
|
use crate::common::wallpapers::Wallpaper;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use rocket::get;
|
use rocket::{get, State};
|
||||||
|
|
||||||
#[derive(rocket::Responder)]
|
#[derive(rocket::Responder)]
|
||||||
#[response(content_type = "text/html")]
|
#[response(content_type = "text/html")]
|
||||||
|
|
@ -28,12 +28,12 @@ pub fn not_found() -> LeptosResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/?<wallpaper>")]
|
#[get("/?<wallpaper>")]
|
||||||
pub async fn root_route(wallpaper: Option<&str>) -> LeptosResponder {
|
pub async fn root_route(wallpaper: Option<&str>, config: &State<crate::Config>) -> LeptosResponder {
|
||||||
let wallpaper = wallpaper
|
let wallpaper = wallpaper
|
||||||
.and_then(Wallpaper::find)
|
.and_then(Wallpaper::find)
|
||||||
.or_else(Wallpaper::random);
|
.or_else(Wallpaper::random);
|
||||||
|
|
||||||
let mut blog = root::Blog::new("https://philippeloctaux.com/blog/atom.xml");
|
let mut blog = root::Blog::new(&config.blog_feed);
|
||||||
if let Err(e) = blog.fetch_feed().await {
|
if let Err(e) = blog.fetch_feed().await {
|
||||||
println!("Failed to get Atom feed: {e}");
|
println!("Failed to get Atom feed: {e}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
# How to launch binary
|
# How to launch binary
|
||||||
plcom = pkgs.writeShellScriptBin "plcom" ''
|
plcom = pkgs.writeShellScriptBin "plcom" ''
|
||||||
PLCOM_ASSETS_PATH=${plcomAssets} ${plcomBinary}/bin/plcom
|
PLCOM_ASSETS=${plcomAssets} PLCOM_BLOG_FEED=/var/www/blog/current/www/atom.xml ${plcomBinary}/bin/plcom
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue