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>,
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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))
|
2020-05-09 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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))
|
2020-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 14:17:18 +00:00
|
|
|
#[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))
|
2020-06-14 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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))
|
2020-06-14 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-14 14:17:18 +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))
|
2020-06-14 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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))
|
2020-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:50:04 +00:00
|
|
|
#[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))
|
2020-08-22 14:50:04 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 09:41:03 +00:00
|
|
|
#[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))
|
2020-09-05 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 14:50:04 +00:00
|
|
|
#[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-08-22 14:50:04 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-09 14:51:18 +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))
|
2020-07-09 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 12:19:28 +00:00
|
|
|
#[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))
|
2020-08-25 12:19:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 13:21:04 +00:00
|
|
|
#[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))
|
2021-01-14 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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))
|
2020-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 18:32:18 +00:00
|
|
|
#[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))
|
2020-05-09 18:32:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 14:26:07 +00:00
|
|
|
#[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))
|
2020-06-28 14:26:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 16:43:20 +00:00
|
|
|
#[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))
|
2020-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 14:17:18 +00:00
|
|
|
#[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-14 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-15 10:35:17 +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-15 10:35:17 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-28 14:26:07 +00:00
|
|
|
#[get("/projects")]
|
|
|
|
fn projects() -> Template {
|
2020-05-10 16:43:20 +00:00
|
|
|
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-05-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 16:06:00 +00:00
|
|
|
#[get("/support")]
|
|
|
|
fn support() -> Template {
|
2020-05-10 16:43:20 +00:00
|
|
|
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-10 16:43:20 +00:00
|
|
|
}
|
|
|
|
|
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()
|
2020-05-10 16:43:20 +00:00
|
|
|
.mount(
|
|
|
|
"/",
|
|
|
|
routes![
|
2020-06-07 16:06:00 +00:00
|
|
|
art,
|
|
|
|
background,
|
|
|
|
bacteria,
|
2020-06-14 14:17:18 +00:00
|
|
|
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,
|
2020-06-14 14:17:18 +00:00
|
|
|
computers_rust_compilation,
|
2020-06-07 16:06:00 +00:00
|
|
|
fungi,
|
2020-08-22 14:50:04 +00:00
|
|
|
fungi_design_patterns,
|
2020-09-05 09:41:03 +00:00
|
|
|
fungi_glossary,
|
2020-08-22 14:50:04 +00:00
|
|
|
fungi_grow_forests,
|
2020-06-07 16:06:00 +00:00
|
|
|
fungi_grow_together,
|
|
|
|
fungi_lichen_space,
|
2020-07-09 14:51:18 +00:00
|
|
|
fungi_network_resilience,
|
2020-08-25 12:19:28 +00:00
|
|
|
fungi_photo_guide,
|
2021-01-14 13:21:04 +00:00
|
|
|
fungi_reading_list,
|
2020-06-07 16:06:00 +00:00
|
|
|
home,
|
|
|
|
lists,
|
2020-06-28 14:26:07 +00:00
|
|
|
meditation,
|
2020-06-07 16:06:00 +00:00
|
|
|
plants,
|
2020-06-14 14:17:18 +00:00
|
|
|
plants_aloe_there,
|
2020-06-10 18:58:43 +00:00
|
|
|
plants_blueberry_dance,
|
2020-06-15 10:35:17 +00:00
|
|
|
plants_botanical_deceptions,
|
2020-06-07 16:06:00 +00:00
|
|
|
plants_potato_tech,
|
2020-06-28 14:26:07 +00:00
|
|
|
projects,
|
2020-06-07 16:06:00 +00:00
|
|
|
support
|
2020-05-10 16:43:20 +00:00
|
|
|
],
|
|
|
|
)
|
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())
|
|
|
|
}
|