grace/htmlua
HTML Templating Engine
git clone https://git.gae.moe/grace/htmlua
23885ab
httpstdlib
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 10let pages = PathBuf :: from ( "/var/www/htmlua/pages" ) ; 11let components = PathBuf :: from ( "/var/www/htmlua/components" ) ; 12let safe_path = Path :: new ( request_uri ) . strip_prefix ( "/" ) ? ; 13let page_path = pages . join ( safe_path ) ; 14 15let doc = read_doc_from_file ( page_path ) ? ; 16 17let full_doc = expand_template ( doc , & components , None ) ? ; 18let markdown_doc = process_markdown ( full_doc ) ? ; 19let highlighted_doc = process_syntax_highlighting ( markdown_doc ) ? ; 20let executed_doc = execute_lua ( highlighted_doc ) ? ; 21Ok ( executed_doc . to_string ()) 22}