render: updates for integration with frontends

This commit is contained in:
2026-04-23 20:39:26 -06:00
parent a2ac39db43
commit 1f8eed80c7
3 changed files with 41 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2025 Emma Tebibyte <emma@tebibyte.media> * Copyright (c) 20252026 Emma Tebibyte <emma@tebibyte.media>
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
* *
* This file is part of Mintee. * This file is part of Mintee.
@@ -26,27 +26,22 @@ use std::{
use tera::{ Context, Tera }; use tera::{ Context, Tera };
/* TODO: silt needs to export the HTTP error types */
#[non_exhaustive]
pub enum PageError {
NotFound,
}
#[non_exhaustive] #[non_exhaustive]
pub enum PageKind { pub enum PageKind {
Code, Code,
Dashboard, Dashboard,
Tickets, Tickets,
Project,
RawCode,
Repo,
User, User,
} Invalid(PageError),
impl PageKind {
pub fn render_page(&self, ctx: Context) -> Result<String, Box<dyn Error>> {
let page_dir = self.to_string();
let template = String::from_utf8(Path::new(&page_dir)
.to_path_buf()
.as_mut_os_string()
.as_encoded_bytes()
.to_vec()
)?;
let tera = Tera::new(&page_dir)?;
Ok(tera.render(&template, &ctx)?)
}
} }
impl Display for PageKind { impl Display for PageKind {
@@ -57,9 +52,36 @@ impl Display for PageKind {
Code => "repo/code.html", Code => "repo/code.html",
Dashboard => "dashboard.html", Dashboard => "dashboard.html",
Tickets => "repo/tickets.html", Tickets => "repo/tickets.html",
Repo => "repo/code.html",
User => "user.html", User => "user.html",
_ => "",
}; };
write!(f, "./assets/templates/{}", path) write!(f, "./assets/templates/{}", path)
} }
} }
pub struct Page {
kind: PageKind,
path: String,
branch: Option<String>,
commit: Option<String>,
tag: Option<String>,
}
/*
impl Page {
pub fn render(&self) -> Result<String, Box<dyn Error>> {
let template_dir = self.kind.to_string();
let template = String::from_utf8(Path::new(&template_dir)
.to_path_buf()
.as_mut_os_string()
.as_encoded_bytes()
.to_vec()
)?;
let tera = Tera::new(&page_dir)?;
Ok(tera.render(&template, &ctx)?)
}
}
*/

View File

@@ -24,7 +24,7 @@ use std::{
}; };
use gix::open; use gix::open;
use tera::{ Context, Tera }; use tera::Tera;
use mintee::backend::git::repo_to_context; use mintee::backend::git::repo_to_context;
@@ -81,7 +81,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let tera = Tera::new(templates.as_str())?; let tera = Tera::new(templates.as_str())?;
let ctx = repo_to_context(open(current_dir()?)?)?; let ctx = repo_to_context(open(current_dir()?)?)?;
println!("{}", tera.render("code.html", &ctx)?); println!("{}", tera.render("repo.html", &ctx)?);
Ok(()) Ok(())
} else { } else {