nib/
config.rs

1use serde_derive::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Deserialize)]
5pub struct Config {
6    pub authors: Option<Vec<String>>,
7    pub build: Build,
8    pub website: Website,
9}
10
11#[derive(Deserialize, Serialize)]
12pub struct Metadata {
13    pub authors: Option<Vec<Author>>,
14}
15
16#[derive(Deserialize, Serialize)]
17pub struct Website {
18    include: Option<Vec<String>>,
19    lang: Option<String>,
20
21    pub description: String,
22    pub license: Option<String>,
23    pub metadata: Option<Metadata>,
24    pub theme: Option<String>,
25    pub title: String,
26    pub url: String,
27}
28
29impl Website {
30    pub fn get_include(&self) -> Vec<String> {
31        self.include
32            .clone()
33            .unwrap_or_else(|| vec!["blog/**/*".to_string()])
34    }
35
36    pub fn get_lang(&self) -> String {
37        self.lang.clone().unwrap_or_else(|| "en".to_string())
38    }
39
40    pub fn to_json(&self) -> Value {
41        json!(self)
42    }
43}
44
45#[derive(Deserialize)]
46pub struct Build {
47    target_dir: Option<String>,
48}
49
50const DST_DIR: &str = "dst";
51
52impl Build {
53    pub fn get_target_dir(&self) -> String {
54        self.target_dir
55            .clone()
56            .unwrap_or_else(|| DST_DIR.to_string())
57    }
58}
59
60#[derive(Deserialize, Serialize)]
61pub struct Author {
62    pub avatar: Option<String>,
63    pub bio: Option<String>,
64    pub email: Option<String>,
65    pub name: String,
66    pub nick: Option<String>,
67}
68
69impl Author {
70    pub fn to_json(&self) -> Value {
71        json!(self)
72    }
73}