Newer
Older
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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>>,
}