diff --git a/src/main.rs b/src/main.rs index 6840c2c..30d8ee2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ struct State { garden_dir: PathBuf, index_file: Option, title: Option, + server_name: String, tera: Tera, } @@ -84,6 +85,13 @@ fn main() -> anyhow::Result<()> { .short("t") .long("title") .help("Title of this digital garden."), + ) + .arg( + Arg::with_name("SERVER_NAME") + .takes_value(true) + .short("u") + .long("garden-url") + .help("Hostname of the server of this digital garden (for metadata)."), ); let matches = app.get_matches(); @@ -115,6 +123,11 @@ fn main() -> anyhow::Result<()> { garden_dir: directory.to_path_buf(), index_file: matches.value_of("INDEX_FILE").map(|s| s.to_string()), title: matches.value_of("TITLE").map(|s| s.to_string()), + server_name: matches + .value_of("SERVER_NAME") + .map_or(matches.value_of("BIND").unwrap().to_string(), |s| { + s.to_string() + }), tera, }; @@ -167,9 +180,7 @@ async fn render( let full_path = data.garden_dir.join(path.as_str()); // Redirect to ".md" version if requested path matches a .md file without the extension - if !full_path.exists() - && Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists() - { + if !full_path.exists() && Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists() { return Ok(HttpResponse::Found() .header(http::header::LOCATION, format!("{}.md", path.to_string())) .finish()); @@ -241,6 +252,8 @@ async fn render( None => None, }, ); + context.insert("server_name", &data.server_name); + context.insert("path", &path.to_string()); Ok(HttpResponse::Ok().body( data.tera diff --git a/templates/favicon.png b/templates/favicon.png new file mode 100644 index 0000000..d3103c4 Binary files /dev/null and b/templates/favicon.png differ diff --git a/templates/main.html b/templates/main.html index ecf9414..b52ccf3 100644 --- a/templates/main.html +++ b/templates/main.html @@ -9,6 +9,12 @@ href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400;1,700&family=Montserrat&display=swap" rel="stylesheet"> + + + + + +