diff --git a/async-git/src/plumbing/ref.rs b/async-git/src/plumbing/ref.rs index 907fbfe..ecdfadc 100644 --- a/async-git/src/plumbing/ref.rs +++ b/async-git/src/plumbing/ref.rs @@ -9,9 +9,7 @@ pub struct Ref { impl Ref { pub fn parse(string: impl AsRef) -> Result { let string = string.as_ref(); - if string.starts_with("ref") { - - } + if string.starts_with("ref") {} unimplemented!() } diff --git a/fedhub/src/lib.rs b/fedhub/src/lib.rs index dbaee90..be1d2a5 100644 --- a/fedhub/src/lib.rs +++ b/fedhub/src/lib.rs @@ -250,20 +250,21 @@ impl Fedhub { let mut ctx = self.context(); ctx.insert("repo_name", &path); ctx.insert("tree_name", &tree_name); - let contents = if blob.is_binary() { - json!(null) - } else { + let mut blob_val = json!({ + "name": filepath, + "binary": blob.is_binary(), + }); + if !blob.is_binary() { let str_contents = String::from_utf8(blob.content().to_vec())?; - json!(str_contents.lines().collect::>()) + if let Some(ext) = filepath.extension() { + if ext.to_str().unwrap() == "md" { + blob_val["rendered"] = + json!(markdown_to_html(&str_contents, &ComrakOptions::default())); + } + } + blob_val["lines"] = json!(str_contents.lines().collect::>()); }; - ctx.insert( - "blob", - &json!({ - "name": filepath, - "binary": blob.is_binary(), - "lines": contents, - }), - ); + ctx.insert("blob", &blob_val); render_response("repo_blob.html", &ctx) } diff --git a/fedhub/src/main.rs b/fedhub/src/main.rs index 28b2796..918b1bc 100644 --- a/fedhub/src/main.rs +++ b/fedhub/src/main.rs @@ -1,7 +1,7 @@ -use std::path::PathBuf; use std::convert::Infallible; use std::fs::File; use std::io::Read; +use std::path::PathBuf; use anyhow::Result; use fedhub::{Config, Fedhub}; diff --git a/fedhub/templates/repo_blob.html b/fedhub/templates/repo_blob.html index 55b5246..5d1f8f8 100644 --- a/fedhub/templates/repo_blob.html +++ b/fedhub/templates/repo_blob.html @@ -5,7 +5,11 @@ {% block content %}

{{ repo_name }}: {{ tree_name }}: {{ blob.name }}

- {% if blob.lines %} + {% if blob.rendered %} +
+ {{ blob.rendered | safe }} +
+ {% elif blob.lines %}