Newer
Older
use regex::{Captures, Regex};
use serde::{Deserialize, Serialize};
// const CSS_LINK_FRAGMENT: &'static str = "<link rel='stylesheet' href='{url}'>";
// const SCRIPT_FRAGMENT: &'static str = "<script src='{url}'></script>";
const HTML_DOC_TEMPLATE: &'static str = "
<html lang='{lang}'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta name='description' content='{description}'>
<title>{title}</title>
</html>
";
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct HtmlDoc(String);
impl HtmlDoc {
let re = Regex::new(r#"\{[a-z]+\}"#).unwrap();
let html = re
.replace_all(HTML_DOC_TEMPLATE, |captures: &Captures| {
let placeholder = captures.iter().next().unwrap().unwrap().as_str();
let placeholder = placeholder[1..placeholder.len() - 1].to_owned(); // strip the brackets
pub fn empty() -> Self {
HtmlDoc(String::new())
}
impl std::fmt::Display for HtmlDoc {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)