From ebf5337ff1075aa9138f9d02ab9c52af41c8890b Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sat, 13 Aug 2022 22:00:41 -0400 Subject: Edit Readme struct to remove render bool --- src/listing.rs | 27 ++++++++------------------- src/renderer.rs | 8 ++++---- 2 files changed, 12 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/listing.rs b/src/listing.rs index 3a54118..6f9e485 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -149,22 +149,12 @@ impl Breadcrumb { /// Readme file information pub struct Readme { - pub render: bool, - pub path: Option, - pub filename: Option, - pub contents: Option, + pub path: PathBuf, + pub filename: String, + pub contents: String, } impl Readme { - fn blank() -> Self { - Readme { - render: false, - path: None, - filename: None, - contents: None, - } - } - fn new(root: PathBuf, base: &Path, filename: String) -> Self { let file_path = root .canonicalize() @@ -183,10 +173,9 @@ impl Readme { &ComrakOptions::default(), ); Readme { - render: true, - path: Some(file_path), - filename: Some(filename), - contents: Some(contents), + path: file_path, + filename, + contents, } } } @@ -277,7 +266,7 @@ pub fn directory_listing( } let mut entries: Vec = Vec::new(); - let mut readme = Readme::blank(); + let mut readme: Option = None; for entry in dir.path.read_dir()? { if dir.is_visible(&entry) || conf.show_hidden { @@ -329,7 +318,7 @@ pub fn directory_listing( symlink_dest, )); if conf.readme && file_name.to_lowercase() == "readme.md" { - readme = Readme::new(conf.path.clone(), base, file_name) + readme = Some(Readme::new(conf.path.clone(), base, file_name)); } } } else { diff --git a/src/renderer.rs b/src/renderer.rs index bafddaf..1e92cbe 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -14,7 +14,7 @@ use crate::{archive::ArchiveMethod, MiniserveConfig}; /// Renders the file listing pub fn page( entries: Vec, - readme: Readme, + readme: Option, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec, @@ -167,10 +167,10 @@ pub fn page( } } } - @if readme.render { + @if readme.is_some() { div { - h3 { (readme.filename.unwrap()) } - (PreEscaped (readme.contents.unwrap())); + h3 { (readme.as_ref().unwrap().filename) } + (PreEscaped (readme.unwrap().contents)); } } a.back href="#top" { -- cgit v1.2.3