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 {
|
||||
pub fn parse(string: impl AsRef<str>) -> Result<Self> {
|
||||
let string = string.as_ref();
|
||||
if string.starts_with("ref") {
|
||||
|
||||
}
|
||||
if string.starts_with("ref") {}
|
||||
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
@ -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::<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",
|
||||
&json!({
|
||||
"name": filepath,
|
||||
"binary": blob.is_binary(),
|
||||
"lines": contents,
|
||||
}),
|
||||
);
|
||||
ctx.insert("blob", &blob_val);
|
||||
render_response("repo_blob.html", &ctx)
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
{% block content %}
|
||||
<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="left">
|
||||
<ul>
|
||||
|
|
Loading…
Reference in a new issue