~zethra/stargazer

72f642cc156231c4f16e0df63587eb256a788627 — Sashanoraa 10 days ago 2e41b73 f.templating
fixup! fixup! Add basic Jinja templating

Signed-off-by: Sashanoraa <sasha@noraa.gay>
2 files changed, 14 insertions(+), 3 deletions(-)

M src/config/template.rs
M src/get_file.rs
M src/config/template.rs => src/config/template.rs +11 -0
@@ 13,8 13,11 @@ pub fn get_env() -> Environment<'static> {
    let mut env = Environment::new();
    env.add_function("load_text", load_text);
    env.add_function("file_list", file_list);

    env.add_filter("dirs_first", dirs_first);
    env.add_filter("sort_files", sort_files);
    env.add_filter("lines", lines);
    env.add_filter("split", split);
    env
}



@@ 212,3 215,11 @@ fn load_text(state: &State, path: String) -> Result<String, Error> {
        )),
    }
}

fn lines(_state: &State, text: String) -> Result<Vec<String>, Error> {
    Ok(text.lines().map(|s| s.to_owned()).collect())
}

fn split(_state: &State, text: String, pattern: String) -> Result<Vec<String>, Error> {
    Ok(text.split(&pattern).map(|s| s.to_owned()).collect())
}

M src/get_file.rs => src/get_file.rs +3 -3
@@ 49,7 49,8 @@ pub async fn get_file<'a>(
    log::debug!("Requested file path: {}", path.display());

    let mut path_string = path_str.to_owned();
    let template_info = get_template(static_route, &path);
    let index_path = path.join(&static_route.index);
    let template_info = get_template(static_route, &path).or_else(|| get_template(static_route, &index_path));
    let has_template = template_info.is_some();
    let (path, path_type, mut mime_type) = unblock(move || {
        if !path.exists() && !has_template {


@@ 62,8 63,7 @@ pub async fn get_file<'a>(
                path_string.push('/');
                return Err(GemError::Redirect(path_string));
            }
            let index_path = path.join(&static_route.index);
            if index_path.exists() {
            if index_path.exists() || has_template {
                let mime_type = get_mime_type(&index_path);
                return Ok((index_path, PathType::File, mime_type));
            }