use crate::website::html::HtmlDoc; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PageData { pub title: String, pub lang: String, pub description: String, pub slug: String, pub html_body: String, pub css_src: Option<String>, pub js_src: Option<String>, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct WebPage { pub page_data: PageData, pub html_doc: HtmlDoc, } impl PageData { pub fn to_web_page(&self) -> WebPage { WebPage { page_data: self.clone(), html_doc: HtmlDoc::from_page_data(&self), } } pub fn field_from_str_key(&self, key: String) -> String { match &key[..] { "title" => self.title.to_owned(), "lang" => self.lang.to_owned(), "description" => self.description.to_owned(), "slug" => self.slug.to_owned(), "body" => self.html_body.to_owned(), "css" => self.css_src.as_ref().unwrap_or(&String::new()).to_owned(), "js" => self.js_src.as_ref().unwrap_or(&String::new()).to_owned(), _ => String::new(), } } } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PagesTree { pub page_data: PageData, pub sub_pages: Option<Vec<PagesTree>>, }