diff options
author | Gaurav <allmanpride@gmail.com> | 2022-08-03 03:07:36 +0000 |
---|---|---|
committer | Gaurav <allmanpride@gmail.com> | 2022-08-14 00:03:55 +0000 |
commit | 03f798d71508cf0fe1856fce6e107229065c06cc (patch) | |
tree | 31574beb66346bfa2b7ec80da6146dc0a4e5764d /src/renderer.rs | |
parent | Add `--readme` flag to cli (diff) | |
download | miniserve-03f798d71508cf0fe1856fce6e107229065c06cc.tar.gz miniserve-03f798d71508cf0fe1856fce6e107229065c06cc.zip |
Replace `markdown` by `comrak`; Render support for nested dirs
* README.md will be rendered at currently visiting directory instead
of just in the root.
* Rendering is now done by comrak, which seems heavy but has a lot
more features.
Diffstat (limited to '')
-rw-r--r-- | src/renderer.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 775d7c8..5fdd2be 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -3,9 +3,10 @@ use chrono::{DateTime, Utc}; use chrono_humanize::Humanize; use clap::{crate_name, crate_version}; use maud::{html, Markup, PreEscaped, DOCTYPE}; +use std::path::PathBuf; use std::time::SystemTime; use strum::IntoEnumIterator; -use std::path::Path; +use comrak::{markdown_to_html, ComrakOptions}; use crate::auth::CurrentUser; use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder}; @@ -14,7 +15,7 @@ use crate::{archive::ArchiveMethod, MiniserveConfig}; /// Renders the file listing pub fn page( entries: Vec<Entry>, - readme: Option<String>, + readme: Option<PathBuf>, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec<Breadcrumb>, @@ -169,9 +170,13 @@ pub fn page( } @if readme.is_some() { div { - h3 { (readme.as_ref().unwrap()) } + h3 { (readme.as_ref().unwrap().file_name().unwrap() + .to_string_lossy().to_string()) } (PreEscaped - (markdown::file_to_html(Path::new(&readme.unwrap())).unwrap())); + (markdown_to_html( + &std::fs::read_to_string(readme.unwrap()) + .unwrap_or_else(|_| "Cannot read File.".to_string()), + &ComrakOptions::default()))); } } a.back href="#top" { |