blob: b235c84741f86809af91ac06d36326ec2c746f41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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))
}
|