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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Deserialize)]
pub struct Config {
    pub authors: Option<Vec<String>>,
    pub build: Build,
    pub website: Website,
}

#[derive(Deserialize, Serialize)]
pub struct Metadata {
    pub authors: Option<Vec<Author>>,
}

#[derive(Deserialize, Serialize)]
pub struct Website {
    include: Option<Vec<String>>,
    lang: Option<String>,

    pub description: String,
    pub license: Option<String>,
    pub metadata: Option<Metadata>,
    pub theme: Option<String>,
    pub title: String,
    pub url: String,
}

impl Website {
    pub fn get_include(&self) -> Vec<String> {
        self.include
            .clone()
            .unwrap_or_else(|| vec!["blog/**/*".to_string()])
    }

    pub fn get_lang(&self) -> String {
        self.lang.clone().unwrap_or_else(|| "en".to_string())
    }

    pub fn to_json(&self) -> Value {
        json!(self)
    }
}

#[derive(Deserialize)]
pub struct Build {
    target_dir: Option<String>,
}

const DST_DIR: &str = "dst";

impl Build {
    pub fn get_target_dir(&self) -> String {
        self.target_dir
            .clone()
            .unwrap_or_else(|| DST_DIR.to_string())
    }
}

#[derive(Deserialize, Serialize)]
pub struct Author {
    pub avatar: Option<String>,
    pub bio: Option<String>,
    pub email: Option<String>,
    pub name: String,
    pub nick: Option<String>,
}

impl Author {
    pub fn to_json(&self) -> Value {
        json!(self)
    }
}