aboutsummaryrefslogtreecommitdiff
path: root/htmlua-apache-cgi/src/main.rs
blob: ce86dc690a6dde9ed6c8e4377aded95cb4caedea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::env;
use std::fs;
use std::fs::read_to_string;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use htmlua_parser::serve::serve_content;
use kuchikiki::{
    NodeRef,
    traits::TendrilSink,
};

fn main() {
    println!("Content-Type: text/html\n");

    let request_uri = env::var("PATH_INFO").unwrap_or_else(|_| "".to_string());

    let page = serve_content(request_uri.as_str()).unwrap();


    // Output the final expanded HTML
    println!("{page}");
}

// Simple HTML escape function
fn html_escape(input: &str) -> String {
    input
        .replace('&', "&")
        .replace('<', "&lt;")
        .replace('>', "&gt;")
        .replace('"', "&quot;")
        .replace('\'', "&#x27;")
}