From b018457e54c66862f163cb5aacbca71a3321c9ae Mon Sep 17 00:00:00 2001 From: Gaurav Date: Tue, 2 Aug 2022 20:44:10 -0400 Subject: Add support for readme rendering --- src/renderer.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/renderer.rs') 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, + readme: Option, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec, @@ -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()) } -- cgit v1.2.3 From 03f798d71508cf0fe1856fce6e107229065c06cc Mon Sep 17 00:00:00 2001 From: Gaurav Date: Tue, 2 Aug 2022 23:07:36 -0400 Subject: 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. --- src/renderer.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/renderer.rs') 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, - readme: Option, + readme: Option, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec, @@ -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" { -- cgit v1.2.3 From f56840a4c04b18fcc6955d7105d32ec9bd6b01dd Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 3 Aug 2022 20:03:37 -0400 Subject: Satisfy cargo fmt --- src/renderer.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/renderer.rs') 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()) } -- cgit v1.2.3 From 19ab9c632e4a12dd7c7c30f56317bf26cb0e3f2f Mon Sep 17 00:00:00 2001 From: Gaurav Date: Thu, 11 Aug 2022 21:46:56 -0400 Subject: Add `--readme` info and reformat --- src/renderer.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/renderer.rs') diff --git a/src/renderer.rs b/src/renderer.rs index 3ce985b..abf6053 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -12,6 +12,7 @@ use crate::auth::CurrentUser; use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder}; use crate::{archive::ArchiveMethod, MiniserveConfig}; +#[allow(clippy::too_many_arguments)] /// Renders the file listing pub fn page( entries: Vec, @@ -169,15 +170,15 @@ 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()))); - } + 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()) -- cgit v1.2.3 From 04ec70e10400642df96c9ffd4eb4daf19cf44df9 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sat, 13 Aug 2022 21:09:02 -0400 Subject: Make Readme struct --- src/renderer.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/renderer.rs') diff --git a/src/renderer.rs b/src/renderer.rs index abf6053..bafddaf 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -2,21 +2,19 @@ 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 crate::auth::CurrentUser; -use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder}; +use crate::listing::{Breadcrumb, Entry, QueryParameters, Readme, SortingMethod, SortingOrder}; use crate::{archive::ArchiveMethod, MiniserveConfig}; #[allow(clippy::too_many_arguments)] /// Renders the file listing pub fn page( entries: Vec, - readme: Option, + readme: Readme, is_root: bool, query_params: QueryParameters, breadcrumbs: Vec, @@ -169,15 +167,10 @@ pub fn page( } } } - @if readme.is_some() { + @if readme.render { 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()))); + h3 { (readme.filename.unwrap()) } + (PreEscaped (readme.contents.unwrap())); } } a.back href="#top" { -- cgit v1.2.3 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/renderer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/renderer.rs') 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