diff --git a/Cargo.lock b/Cargo.lock index 974ee1f..f15a505 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2036,6 +2036,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "y10n" version = "0.1.0" +source = "git+https://github.com/rtyler/y10n?branch=main#877a3c95dd2de2f1796c2e6e587dc1dcbcd64520" dependencies = [ "glob", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index efadb68..745b975 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ glob = "0" handlebars = { version = "4", features = ["dir_source"] } log = "*" pretty_env_logger = "0.3" -# Used for embedding templates +# Used for embedding templates, etc for an all in one binary rust-embed = "5" # All the object serialization for APIs and persisting data on disk @@ -28,4 +28,4 @@ serde_yaml = "0.8" tide = "*" # Localization support -y10n = { "path" = "../y10n" } +y10n = { "git" = "https://github.com/rtyler/y10n", branch = "main" } diff --git a/src/main.rs b/src/main.rs index b64053d..c18d5bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ extern crate serde_json; use log::*; mod dao; +mod routes; mod state; #[async_std::main] @@ -23,21 +24,7 @@ async fn main() -> Result<(), std::io::Error> { let state = AppState::new(); let mut app = tide::with_state(state); - - app.at("/") - .get(|req: tide::Request>| async move { - let data = json!({ - "projects" : dao::v1::Project::load_all(), - }); - let lang = match req.header("Accept-Language") { - Some(l) => l.as_str(), - None => "en", - }; - let langs = y10n::parse_accept_language(lang); - info!("Lang: {:?}", langs); - - req.state().render("index", &langs, Some(data)).await - }); + routes::views::register(&mut app); if let Some(fd) = std::env::var("LISTEN_FD") .ok() diff --git a/src/routes/mod.rs b/src/routes/mod.rs new file mode 100644 index 0000000..50ca83a --- /dev/null +++ b/src/routes/mod.rs @@ -0,0 +1,4 @@ +/** + * This module contains all the re-exported routes for different aspects of Geoffrey + */ +pub mod views; diff --git a/src/routes/views.rs b/src/routes/views.rs new file mode 100644 index 0000000..043d67c --- /dev/null +++ b/src/routes/views.rs @@ -0,0 +1,25 @@ +use crate::dao::v1::*; +/** + * View routes + */ +use crate::state::*; +use log::*; +use tide::{Body, Request, Server}; + +pub fn register(app: &mut Server>) { + app.at("/").get(index); +} + +async fn index(req: Request>) -> tide::Result { + let data = json!({ + "projects" : Project::load_all(), + }); + let lang = match req.header("Accept-Language") { + Some(l) => l.as_str(), + None => "en", + }; + let langs = y10n::parse_accept_language(lang); + info!("Lang: {:?}", langs); + + req.state().render("index", &langs, Some(data)).await +} diff --git a/views/index.hbs b/views/index.hbs index 81e5411..89e2ce6 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -1,41 +1,65 @@ Geoffrey + - + {{> partials/_header}}
-
diff --git a/views/partials/_header.hbs b/views/partials/_header.hbs new file mode 100644 index 0000000..a2044fb --- /dev/null +++ b/views/partials/_header.hbs @@ -0,0 +1,6 @@ + +