aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGaurav <allmanpride@gmail.com>2022-08-14 02:00:41 +0000
committerGaurav <allmanpride@gmail.com>2022-08-14 02:00:41 +0000
commitebf5337ff1075aa9138f9d02ab9c52af41c8890b (patch)
tree098c95a97b7cd25f770c6f33bc202fa6c3f694b0 /src
parentMake Readme struct (diff)
downloadminiserve-ebf5337ff1075aa9138f9d02ab9c52af41c8890b.tar.gz
miniserve-ebf5337ff1075aa9138f9d02ab9c52af41c8890b.zip
Edit Readme struct to remove render bool
Diffstat (limited to 'src')
-rw-r--r--src/listing.rs27
-rw-r--r--src/renderer.rs8
2 files changed, 12 insertions, 23 deletions
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<PathBuf>,
- pub filename: Option<String>,
- pub contents: Option<String>,
+ 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<Entry> = Vec::new();
- let mut readme = Readme::blank();
+ let mut readme: Option<Readme> = 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<Entry>,
- readme: Readme,
+ readme: Option<Readme>,
is_root: bool,
query_params: QueryParameters,
breadcrumbs: Vec<Breadcrumb>,
@@ -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" {