website/src/main.rs

323 lines
8.0 KiB
Rust
Raw Normal View History

2020-05-08 17:22:06 +00:00
#![feature(proc_macro_hygiene, decl_macro)]
extern crate log;
#[macro_use]
extern crate rocket;
extern crate tera;
2021-10-30 13:24:05 +00:00
use miniserde::{json, Serialize};
2021-10-30 13:12:44 +00:00
use rocket::{
fs::{relative, FileServer},
get, routes,
};
use rocket_dyn_templates::Template;
2020-05-08 17:22:06 +00:00
#[derive(Debug, Serialize)]
struct FlashContext {
flash_name: Option<String>,
flash_msg: Option<String>,
}
#[get("/art")]
fn art() -> Template {
2020-05-08 17:22:06 +00:00
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("art", json::to_string(&context))
2020-05-08 17:22:06 +00:00
}
2020-05-09 14:44:33 +00:00
#[get("/background")]
fn background() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("background", json::to_string(&context))
}
#[get("/bacteria")]
fn bacteria() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("bacteria", json::to_string(&context))
}
#[get("/bacteria/sauerkraut-beginnings")]
fn bacteria_sauerkraut_beginnings() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("bacteria/sauerkraut_beginnings", json::to_string(&context))
}
#[get("/bacteria/sauerkraut-bottled")]
fn bacteria_sauerkraut_bottled() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("bacteria/sauerkraut_bottled", json::to_string(&context))
}
#[get("/computers")]
fn computers() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("computers", json::to_string(&context))
}
2020-06-14 18:19:51 +00:00
#[get("/computers/esp8266-dht11")]
fn computers_esp8266_dht11() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("computers/esp8266_dht11", json::to_string(&context))
2020-06-14 18:19:51 +00:00
}
2020-06-14 20:11:21 +00:00
#[get("/computers/i2c-adventures")]
fn computers_i2c_adventures() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("computers/i2c_adventures", json::to_string(&context))
2020-06-14 20:11:21 +00:00
}
#[get("/computers/rust-compilation")]
fn computers_rust_compilation() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("computers/rust_compilation", json::to_string(&context))
}
#[get("/fungi")]
fn fungi() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi", json::to_string(&context))
}
#[get("/fungi/design-patterns")]
fn fungi_design_patterns() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/design_patterns", json::to_string(&context))
}
#[get("/fungi/glossary")]
fn fungi_glossary() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/glossary", json::to_string(&context))
}
#[get("/fungi/grow-forests")]
fn fungi_grow_forests() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/grow_forests", json::to_string(&context))
}
2020-06-07 16:06:00 +00:00
#[get("/fungi/grow-together")]
fn fungi_grow_together() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/grow_together", json::to_string(&context))
2020-06-07 16:06:00 +00:00
}
#[get("/fungi/lichen-space")]
fn fungi_lichen_space() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/lichen_space", json::to_string(&context))
2020-06-07 16:06:00 +00:00
}
#[get("/fungi/network-resilience")]
fn fungi_network_resilience() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/network_resilience", json::to_string(&context))
}
#[get("/fungi/photo-guide")]
fn fungi_photo_guide() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/photo_guide", json::to_string(&context))
}
#[get("/fungi/reading-list")]
fn fungi_reading_list() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("fungi/reading_list", json::to_string(&context))
}
#[get("/")]
fn home() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("home", json::to_string(&context))
}
#[get("/lists")]
fn lists() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("lists", json::to_string(&context))
}
#[get("/meditation")]
fn meditation() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("meditation", json::to_string(&context))
}
#[get("/plants")]
fn plants() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("plants", json::to_string(&context))
}
#[get("/plants/aloe-there")]
fn plants_aloe_there() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("plants/aloe_there", json::to_string(&context))
}
2020-06-10 18:58:43 +00:00
#[get("/plants/blueberry-dance")]
fn plants_blueberry_dance() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("plants/blueberry_dance", json::to_string(&context))
2020-06-10 18:58:43 +00:00
}
#[get("/plants/botanical-deceptions")]
fn plants_botanical_deceptions() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("plants/botanical_deceptions", json::to_string(&context))
}
2020-06-07 16:06:00 +00:00
#[get("/plants/potato-tech")]
fn plants_potato_tech() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("plants/potato_tech", json::to_string(&context))
2020-06-07 16:06:00 +00:00
}
#[get("/projects")]
fn projects() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("projects", json::to_string(&context))
}
2020-06-07 16:06:00 +00:00
#[get("/support")]
fn support() -> Template {
let context = FlashContext {
flash_name: None,
flash_msg: None,
};
2021-10-30 13:24:05 +00:00
Template::render("support", json::to_string(&context))
}
2020-05-08 17:22:06 +00:00
#[catch(404)]
fn not_found() -> Template {
debug!("404 Page Not Found");
let context = FlashContext {
flash_name: Some("error".to_string()),
flash_msg: Some("No resource found for given URL".to_string()),
};
2021-10-30 13:24:05 +00:00
Template::render("not_found", json::to_string(&context))
2020-05-08 17:22:06 +00:00
}
2021-10-30 13:12:44 +00:00
#[launch]
fn rocket() -> _ {
rocket::build()
.mount(
"/",
routes![
2020-06-07 16:06:00 +00:00
art,
background,
bacteria,
bacteria_sauerkraut_beginnings,
bacteria_sauerkraut_bottled,
2020-06-07 16:06:00 +00:00
computers,
2020-06-14 18:19:51 +00:00
computers_esp8266_dht11,
2020-06-14 20:11:21 +00:00
computers_i2c_adventures,
computers_rust_compilation,
2020-06-07 16:06:00 +00:00
fungi,
fungi_design_patterns,
fungi_glossary,
fungi_grow_forests,
2020-06-07 16:06:00 +00:00
fungi_grow_together,
fungi_lichen_space,
fungi_network_resilience,
fungi_photo_guide,
fungi_reading_list,
2020-06-07 16:06:00 +00:00
home,
lists,
meditation,
2020-06-07 16:06:00 +00:00
plants,
plants_aloe_there,
2020-06-10 18:58:43 +00:00
plants_blueberry_dance,
plants_botanical_deceptions,
2020-06-07 16:06:00 +00:00
plants_potato_tech,
projects,
2020-06-07 16:06:00 +00:00
support
],
)
2021-10-30 13:12:44 +00:00
.mount("/", FileServer::from(relative!("static")))
.register("/", catchers![not_found])
2020-05-08 17:22:06 +00:00
.attach(Template::fairing())
}