diff options
| author | gyoder <70408179+gyoder@users.noreply.github.com> | 2025-07-12 22:02:53 -0600 |
|---|---|---|
| committer | gyoder <70408179+gyoder@users.noreply.github.com> | 2025-07-12 22:02:53 -0600 |
| commit | 5ed6fdebb4ba46c283daf5e76fb46820589b7c69 (patch) | |
| tree | 908d5e5f5bc8dc2d63a54c62a976131cc6fa5f86 /htmlua-parser/src/serve.rs | |
| parent | 085aa5a1f553d4acb2acc7ac7d74690e9326a3a5 (diff) | |
| parent | d9efc151c051577b7de843ac249c360917d36736 (diff) | |
Merge branch 'main' into httpstdlib
Diffstat (limited to 'htmlua-parser/src/serve.rs')
| -rw-r--r-- | htmlua-parser/src/serve.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/htmlua-parser/src/serve.rs b/htmlua-parser/src/serve.rs index cfb3811..9821210 100644 --- a/htmlua-parser/src/serve.rs +++ b/htmlua-parser/src/serve.rs @@ -1,19 +1,29 @@ -use crate::helpers::read_doc_from_file; - -use super::render::{execute_lua, expand_template, process_markdown, process_syntax_highlighting}; +use crate::{ + config::Config, + helpers::read_doc_from_file, + render::{execute_lua, expand_template, process_markdown, process_syntax_highlighting}, +}; use anyhow::Result; -use std::path::{Path, PathBuf}; +use std::{path::Path, sync::OnceLock}; + +static CONFIG: OnceLock<Config> = OnceLock::new(); + +pub fn get_config() -> &'static Config { + CONFIG.get_or_init(|| { + Config::load().unwrap_or_else(|e| { + eprintln!("Warning: Failed to load config: {}", e); + eprintln!("Using default configuration"); + Config::default() + }) + }) +} pub fn serve_content(request_uri: &str) -> Result<String> { - // TODO: read from config - let pages = PathBuf::from("/var/www/htmlua/pages"); - let components = PathBuf::from("/var/www/htmlua/components"); + let config = get_config(); let safe_path = Path::new(request_uri).strip_prefix("/")?; - let page_path = pages.join(safe_path); - + let page_path = config.paths.pages.join(safe_path); let doc = read_doc_from_file(page_path)?; - - let full_doc = expand_template(doc, &components, None)?; + let full_doc = expand_template(doc, &config.paths.components, None)?; let markdown_doc = process_markdown(full_doc)?; let highlighted_doc = process_syntax_highlighting(markdown_doc)?; let executed_doc = execute_lua(highlighted_doc)?; |
