Added support for <markdown>. Closes #4.

This commit is contained in:
Quin 2025-07-05 22:04:27 -06:00
parent 88b22b4e77
commit 8e25531af1
4 changed files with 105 additions and 17 deletions

View file

@ -1,24 +1,21 @@
use super::render::execute_lua;
use super::render::expand_template;
use super::render::{execute_lua, expand_template, process_markdown};
use anyhow::Result;
use kuchikiki::traits::TendrilSink;
use std::fs::read_to_string;
use std::path::{Path, PathBuf};
use std::{
fs::read_to_string,
path::{Path, PathBuf},
};
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 safe_path = Path::new(request_uri).strip_prefix("/")?;
let page_path = pages.join(safe_path);
let page_string = read_to_string(&page_path)?;
let doc = kuchikiki::parse_html().one(page_string);
let full_doc = expand_template(doc, &components, None)?;
let executed_doc = execute_lua(full_doc)?;
let markdown_doc = process_markdown(full_doc)?;
let executed_doc = execute_lua(markdown_doc)?;
Ok(executed_doc.to_string())
}