fixes frontend getting resources from backend

This commit is contained in:
2026-05-07 04:24:04 +00:00
parent 014d258a45
commit 9b4cdb95ef
3 changed files with 83 additions and 11 deletions

View File

@@ -1,2 +1,47 @@
/*
* Copyright (c) 2026 Emma Tebibyte <emma@tebibyte.media>
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This file is part of Mintee.
*
* Mintee is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Mintee is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Mintee. If not, see https://www.gnu.org/licenses/.
*/
pub mod git;
pub mod render;
const MINTEE_DIR: &str = "/var/mintee";
const MINTEE_ASSETS: &str = "/usr/local/share/mintee";
pub mod srv {
use std::{
error::Error,
fs::File,
io::{ BufReader, BufWriter, Write, copy },
path::Path,
};
use crate::backend::MINTEE_ASSETS;
pub fn get_res<T, W>(path: T, dest: &mut W) -> Result<(), Box<dyn Error>>
where T: AsRef<Path>, W: Write {
let path_absolute = Path::new(MINTEE_ASSETS).join("res").join(path);
let mut reader = BufReader::new(File::open(path_absolute)?);
let mut writer = BufWriter::new(dest);
copy(&mut reader, &mut writer)?;
Ok(())
}
}

View File

@@ -28,7 +28,11 @@ use std::{
use gix::open;
use tera::Tera;
use crate::backend::git::ToContext;
use crate::backend::{
MINTEE_DIR,
MINTEE_ASSETS,
git::ToContext,
};
#[derive(Debug, Clone)]
/// A revision for which a repository page may be rendered
@@ -134,9 +138,8 @@ impl Page {
pub fn render<W: Write>(
&self, dest: &mut W
) -> Result<(), Box<dyn Error>> {
/* TODO: replace ./assets/ with the actual templates directory,
* i.e. /usr/local/share/mintee/ */
let tera = Tera::new("./assets/templates/**/*")?;
let assets = format!("{}/templates/**/*", MINTEE_ASSETS);
let tera = Tera::new(&assets)?;
let mut page_template = self.kind.to_string();
use PageKind::*;
@@ -145,7 +148,11 @@ impl Page {
todo!()
},
Repo(r) => {
let repo = open(format!("{}/{}", r.entity, r.name))?;
let mut repo_path = PathBuf::from(MINTEE_DIR.to_string());
repo_path.push(r.entity);
repo_path.push(r.name);
let repo = open(repo_path)?;
/* TODO: handle specifying a commit, tag, or branch */
let head_tree = repo.head_tree()?;
let object;