grace/htmlua

HTML Templating Engine

git clone https://git.gae.moe/grace/htmlua

Grace YoderMerge pull request #8 from trypsynth/syntect23885ab

httpstdlib
831 B22 linesraw
1use crate::helpers::read_doc_from_file;
2
3use super::render::{execute_lua, expand_template, process_markdown, process_syntax_highlighting};
4use anyhow::Result;
5use std::path::{Path, PathBuf}
6;
7
8pub fn serve_content(request_uri: &str) -> Result<String> {
9    // TODO: read from config
10    let pages = PathBuf::from("/var/www/htmlua/pages");
11    let components = PathBuf::from("/var/www/htmlua/components");
12    let safe_path = Path::new(request_uri).strip_prefix("/")?;
13    let page_path = pages.join(safe_path);
14
15    let doc = read_doc_from_file(page_path)?;
16
17    let full_doc = expand_template(doc, &components, None)?;
18    let markdown_doc = process_markdown(full_doc)?;
19    let highlighted_doc = process_syntax_highlighting(markdown_doc)?;
20    let executed_doc = execute_lua(highlighted_doc)?;
21    Ok(executed_doc.to_string())
22}