diff options
author | Gaurav <allmanpride@gmail.com> | 2022-08-03 00:44:10 +0000 |
---|---|---|
committer | Gaurav <allmanpride@gmail.com> | 2022-08-14 00:03:49 +0000 |
commit | b018457e54c66862f163cb5aacbca71a3321c9ae (patch) | |
tree | 1f2384581abfd3b75ec752cb6b17cab38dc44136 | |
parent | Bump deps (diff) | |
download | miniserve-b018457e54c66862f163cb5aacbca71a3321c9ae.tar.gz miniserve-b018457e54c66862f163cb5aacbca71a3321c9ae.zip |
Add support for readme rendering
Diffstat (limited to '')
-rw-r--r-- | Cargo.lock | 18 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/listing.rs | 8 | ||||
-rw-r--r-- | src/renderer.rs | 9 |
4 files changed, 36 insertions, 1 deletions
@@ -1361,6 +1361,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] +name = "markdown" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef3aab6a1d529b112695f72beec5ee80e729cb45af58663ec902c8fac764ecdd" +dependencies = [ + "lazy_static", + "pipeline", + "regex", +] + +[[package]] name = "markup5ever" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1462,6 +1473,7 @@ dependencies = [ "httparse", "libflate", "log", + "markdown", "maud", "mime", "nanoid", @@ -1762,6 +1774,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] +name = "pipeline" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15b6607fa632996eb8a17c9041cb6071cb75ac057abd45dece578723ea8c7c0" + +[[package]] name = "port_check" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -55,6 +55,8 @@ tar = "0.4" thiserror = "1" yansi = "0.5" zip = { version = "0.6.2", default-features = false } +get_if_addrs = "0.5" +markdown = "0.3.0" [features] default = ["tls"] diff --git a/src/listing.rs b/src/listing.rs index 25f50fa..3c77c14 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -232,6 +232,7 @@ pub fn directory_listing( } let mut entries: Vec<Entry> = Vec::new(); + let mut readme: Option<String> = None; for entry in dir.path.read_dir()? { if dir.is_visible(&entry) || conf.show_hidden { @@ -275,13 +276,17 @@ pub fn directory_listing( )); } else if metadata.is_file() { entries.push(Entry::new( - file_name, + file_name.clone(), EntryType::File, file_url, Some(ByteSize::b(metadata.len())), last_modification_date, symlink_dest, )); + // TODO: Pattern match, or user arg for readme name? + if file_name.to_lowercase() == "readme.md"{ + readme = Some(file_name); + } } } else { continue; @@ -372,6 +377,7 @@ pub fn directory_listing( HttpResponse::Ok().content_type(mime::TEXT_HTML_UTF_8).body( renderer::page( entries, + readme, is_root, query_params, breadcrumbs, diff --git a/src/renderer.rs b/src/renderer.rs index 75d2c71..775d7c8 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -5,6 +5,7 @@ use clap::{crate_name, crate_version}; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::time::SystemTime; use strum::IntoEnumIterator; +use std::path::Path; use crate::auth::CurrentUser; use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder}; @@ -13,6 +14,7 @@ use crate::{archive::ArchiveMethod, MiniserveConfig}; /// Renders the file listing pub fn page( entries: Vec<Entry>, + readme: Option<String>, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec<Breadcrumb>, @@ -165,6 +167,13 @@ pub fn page( } } } + @if readme.is_some() { + div { + h3 { (readme.as_ref().unwrap()) } + (PreEscaped + (markdown::file_to_html(Path::new(&readme.unwrap())).unwrap())); + } + } a.back href="#top" { (arrow_up()) } |