diff options
author | Gaurav <allmanpride@gmail.com> | 2022-08-04 00:03:37 +0000 |
---|---|---|
committer | Gaurav <allmanpride@gmail.com> | 2022-08-14 00:03:55 +0000 |
commit | f56840a4c04b18fcc6955d7105d32ec9bd6b01dd (patch) | |
tree | f804a529d7f8bc36ea49e03496149f767158899c /src | |
parent | Replace `markdown` by `comrak`; Render support for nested dirs (diff) | |
download | miniserve-f56840a4c04b18fcc6955d7105d32ec9bd6b01dd.tar.gz miniserve-f56840a4c04b18fcc6955d7105d32ec9bd6b01dd.zip |
Satisfy cargo fmt
Diffstat (limited to '')
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | src/listing.rs | 26 | ||||
-rw-r--r-- | src/renderer.rs | 24 |
3 files changed, 30 insertions, 22 deletions
diff --git a/src/config.rs b/src/config.rs index 9dddeb9..5bcbd62 100644 --- a/src/config.rs +++ b/src/config.rs @@ -259,7 +259,7 @@ impl MiniserveConfig { hide_version_footer: args.hide_version_footer, hide_theme_selector: args.hide_theme_selector, show_wget_footer: args.show_wget_footer, - readme: args.readme, + readme: args.readme, tls_rustls_config: tls_rustls_server_config, }) } diff --git a/src/listing.rs b/src/listing.rs index 436add9..42054ca 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -283,14 +283,22 @@ pub fn directory_listing( last_modification_date, symlink_dest, )); - // TODO: Pattern match? - if conf.readme && file_name.to_lowercase() == "readme.md"{ - let file_path = conf.path.canonicalize().unwrap() - .join(base.as_os_str().to_str().unwrap() - .strip_prefix("/").unwrap()) - .join(&file_name); - readme = Some(file_path); - } + // TODO: Pattern match? + if conf.readme && file_name.to_lowercase() == "readme.md" { + let file_path = conf + .path + .canonicalize() + .unwrap() + .join( + base.as_os_str() + .to_str() + .unwrap() + .strip_prefix('/') + .unwrap(), + ) + .join(&file_name); + readme = Some(file_path); + } } } else { continue; @@ -381,7 +389,7 @@ pub fn directory_listing( HttpResponse::Ok().content_type(mime::TEXT_HTML_UTF_8).body( renderer::page( entries, - readme, + readme, is_root, query_params, breadcrumbs, diff --git a/src/renderer.rs b/src/renderer.rs index 5fdd2be..3ce985b 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -2,11 +2,11 @@ use actix_web::http::StatusCode; use chrono::{DateTime, Utc}; use chrono_humanize::Humanize; use clap::{crate_name, crate_version}; +use comrak::{markdown_to_html, ComrakOptions}; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::path::PathBuf; use std::time::SystemTime; use strum::IntoEnumIterator; -use comrak::{markdown_to_html, ComrakOptions}; use crate::auth::CurrentUser; use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder}; @@ -168,17 +168,17 @@ pub fn page( } } } - @if readme.is_some() { - div { - h3 { (readme.as_ref().unwrap().file_name().unwrap() - .to_string_lossy().to_string()) } - (PreEscaped - (markdown_to_html( - &std::fs::read_to_string(readme.unwrap()) - .unwrap_or_else(|_| "Cannot read File.".to_string()), - &ComrakOptions::default()))); - } - } + @if readme.is_some() { + div { + h3 { (readme.as_ref().unwrap().file_name().unwrap() + .to_string_lossy().to_string()) } + (PreEscaped + (markdown_to_html( + &std::fs::read_to_string(readme.unwrap()) + .unwrap_or_else(|_| "Cannot read File.".to_string()), + &ComrakOptions::default()))); + } + } a.back href="#top" { (arrow_up()) } |