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