aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs7
-rw-r--r--src/templates.rs8
-rw-r--r--templates/repo_file.html17
3 files changed, 31 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 333a4bc..f4e26d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -114,7 +114,12 @@ async fn view_tree_path(state: &Arc<Mutex<State>>, repo_rel_path: &str, tree_rel
};
Ok(template.into())
} else if let Some(selected_blob) = selected_object.as_blob() {
- todo!()
+ let template = templates::RepoFile {
+ title: repo_rel_path,
+ rel_path: &tree_rel_path,
+ blob: selected_blob.clone(),
+ };
+ Ok(template.into())
} else {
panic!()
}
diff --git a/src/templates.rs b/src/templates.rs
index 257c41e..f15046a 100644
--- a/src/templates.rs
+++ b/src/templates.rs
@@ -18,6 +18,14 @@ pub struct RepoFolder<'a> {
pub tree: git2::Tree<'a>,
}
+#[derive(Template)]
+#[template(path = "repo_file.html")]
+pub struct RepoFile<'a> {
+ pub title: &'a str,
+ pub rel_path: &'a str,
+ pub blob: git2::Blob<'a>,
+}
+
mod filters {
pub fn from_utf8_lossy(utf8: &[u8]) -> ::askama::Result<String> {
Ok(String::from_utf8_lossy(utf8).into_owned())
diff --git a/templates/repo_file.html b/templates/repo_file.html
new file mode 100644
index 0000000..e01d02c
--- /dev/null
+++ b/templates/repo_file.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport"
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <title>{{ title }}</title>
+</head>
+<body>
+<h1><a href="/">gityeet</a></h1>
+<p>{{ rel_path }}</p>
+<pre>
+{{ blob.content()|from_utf8_lossy }}
+</pre>
+</body>
+</html>