render markdown docs
This commit is contained in:
parent
2333a02b4f
commit
229f0478e1
4 changed files with 20 additions and 17 deletions
|
@ -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!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
|
||||||
} else {
|
|
||||||
let str_contents = String::from_utf8(blob.content().to_vec())?;
|
|
||||||
json!(str_contents.lines().collect::<Vec<_>>())
|
|
||||||
};
|
|
||||||
ctx.insert(
|
|
||||||
"blob",
|
|
||||||
&json!({
|
|
||||||
"name": filepath,
|
"name": filepath,
|
||||||
"binary": blob.is_binary(),
|
"binary": blob.is_binary(),
|
||||||
"lines": contents,
|
});
|
||||||
}),
|
if !blob.is_binary() {
|
||||||
);
|
let str_contents = String::from_utf8(blob.content().to_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("blob", &blob_val);
|
||||||
render_response("repo_blob.html", &ctx)
|
render_response("repo_blob.html", &ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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};
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue