added apache2 cgi script
This commit is contained in:
parent
93cee58807
commit
7e896c1397
7 changed files with 329 additions and 238 deletions
39
htmlua-parser/src/serve.rs
Normal file
39
htmlua-parser/src/serve.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::read_to_string;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use super::render::execute_lua;
|
||||
use super::render::expand_template;
|
||||
use anyhow::Result;
|
||||
use kuchikiki::{
|
||||
NodeRef,
|
||||
traits::TendrilSink,
|
||||
};
|
||||
|
||||
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)?;
|
||||
|
||||
Ok(executed_doc.to_string())
|
||||
}
|
||||
|
||||
fn html_escape(input: &str) -> String {
|
||||
input
|
||||
.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">")
|
||||
.replace('"', """)
|
||||
.replace('\'', "'")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue