diff options
Diffstat (limited to 'src/handlers.rs')
| -rw-r--r-- | src/handlers.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs new file mode 100644 index 0000000..b235c84 --- /dev/null +++ b/src/handlers.rs @@ -0,0 +1,28 @@ +use askama::Template; +use axum::{extract::State, response::Html}; + +use crate::{ + Result, + config::Config, + models::{Bookmarks, Section}, +}; + +#[derive(Template)] +#[template(path = "index.html")] +pub struct MyTemplate { + bookmarks: Vec<Section>, +} + +pub async fn handler(State(config): State<Config>) -> Result<Html<String>> { + let bookmarks = std::fs::read_to_string(config.bookmarks_file)?; + + let bookmarks: Bookmarks = serde_json::from_str(&bookmarks)?; + + let template = MyTemplate { + bookmarks: bookmarks.sections, + }; + + let html = template.render()?; + + Ok(Html(html)) +} |
