render markdown docs

This commit is contained in:
Michael Zhang 2020-04-22 02:52:11 -05:00
parent 2333a02b4f
commit 229f0478e1
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 20 additions and 17 deletions

View file

@ -9,9 +9,7 @@ pub struct Ref {
impl Ref { impl Ref {
pub fn parse(string: impl AsRef<str>) -> Result<Self> { pub fn parse(string: impl AsRef<str>) -> Result<Self> {
let string = string.as_ref(); let string = string.as_ref();
if string.starts_with("ref") { if string.starts_with("ref") {}
}
unimplemented!() unimplemented!()
} }

View file

@ -250,20 +250,21 @@ impl Fedhub {
let mut ctx = self.context(); let mut ctx = self.context();
ctx.insert("repo_name", &path); ctx.insert("repo_name", &path);
ctx.insert("tree_name", &tree_name); ctx.insert("tree_name", &tree_name);
let contents = if blob.is_binary() { let mut blob_val = json!({
json!(null) "name": filepath,
} else { "binary": blob.is_binary(),
});
if !blob.is_binary() {
let str_contents = String::from_utf8(blob.content().to_vec())?; let str_contents = String::from_utf8(blob.content().to_vec())?;
json!(str_contents.lines().collect::<Vec<_>>()) 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::<Vec<_>>());
}; };
ctx.insert( ctx.insert("blob", &blob_val);
"blob",
&json!({
"name": filepath,
"binary": blob.is_binary(),
"lines": contents,
}),
);
render_response("repo_blob.html", &ctx) render_response("repo_blob.html", &ctx)
} }

View file

@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::convert::Infallible; use std::convert::Infallible;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::PathBuf;
use anyhow::Result; use anyhow::Result;
use fedhub::{Config, Fedhub}; use fedhub::{Config, Fedhub};

View file

@ -5,7 +5,11 @@
{% block content %} {% block content %}
<h1>{{ repo_name }}: {{ tree_name }}: {{ blob.name }}</h1> <h1>{{ repo_name }}: {{ tree_name }}: {{ blob.name }}</h1>
{% if blob.lines %} {% if blob.rendered %}
<div>
{{ blob.rendered | safe }}
</div>
{% elif blob.lines %}
<div class="blob-contents"> <div class="blob-contents">
<div class="left"> <div class="left">
<ul> <ul>