diff --git a/config.toml b/config.toml index 6813725..4433727 100644 --- a/config.toml +++ b/config.toml @@ -7,10 +7,20 @@ css = [] before_navbar_url = "test_page/resources/before_navbar.html" before_content_url = "test_page/resources/before_content.html" after_content_url = "test_page/resources/after_content.html" -#favicon = "favicon.png" -#twitter_author = "@teascade" -#google_robots = "all" -#google_site_verification = "" +favicon = "favicon.png" + +charset = "utf-8" +mobile_viewport = true +meta_description = true +meta_og = true + +[google] +google_robots = "all" +google_site_verification = "some_verification" + +[twitter] +twitter_site = "@teascade" +twitter_creator = "@teascade" [navbar] items = ["about", "other", "google"] diff --git a/src/config_toml.rs b/src/config_toml.rs index 2a0a60a..9c9cd6e 100644 --- a/src/config_toml.rs +++ b/src/config_toml.rs @@ -15,6 +15,8 @@ pub struct GlobalConfigToml { pub navbar: Option, #[serde(rename = "resource")] pub resources: Option>, + pub twitter: Option, + pub google: Option, } #[derive(Deserialize, Serialize, Clone, Debug)] @@ -30,13 +32,28 @@ pub struct WebsiteConfig { pub use_default_css: bool, pub javascript: Vec, pub css: Vec, + pub favicon: Option, pub before_navbar_url: Option, pub before_content_url: Option, pub after_content_url: Option, - pub twitter_author: Option, - pub google_robots: Option, - pub google_site_verification: Option, + + pub mobile_viewport: Option, + pub meta_description: Option, + pub charset: Option, + pub meta_og: Option, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct GoogleConfig { + pub google_robots: String, + pub google_site_verification: String, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct TwitterConfig { + pub twitter_site: String, + pub twitter_creator: String, } #[derive(Deserialize, Serialize, Clone, Debug)] diff --git a/src/main.rs b/src/main.rs index a77f9bb..700b3de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,12 +108,16 @@ fn run() -> Result<(), ()> { before_navbar_url: None, before_content_url: None, after_content_url: None, - twitter_author: init_opt.twitter_author, - google_robots: None, - google_site_verification: None, + + mobile_viewport: None, + meta_description: None, + charset: Some("utf-8".to_owned()), + meta_og: None, }, navbar: navbar, resources: None, + twitter: None, + google: None, }; match file_writer::write_toml(&PathBuf::from("config.toml"), &config, opt.overwrite) { diff --git a/src/template.rs b/src/template.rs index 0fb3374..8af9d94 100644 --- a/src/template.rs +++ b/src/template.rs @@ -96,29 +96,26 @@ impl Template { .favicon .unwrap_or(String::new()), ); - let google_robots = config - .global_config - .website - .google_robots - .unwrap_or(String::new()); - let google_verification = config - .global_config - .website - .google_site_verification - .unwrap_or(String::new()); - let twitter_author = config - .global_config - .website - .twitter_author - .unwrap_or(String::new()); + + let mut twitter_site = String::new(); + let mut twitter_creator = String::new(); + if let Some(twitter) = config.global_config.twitter.clone() { + twitter_site = twitter.twitter_site; + twitter_creator = twitter.twitter_creator; + } + + let mut google_robots = String::new(); + let mut google_site_verification = String::new(); + if let Some(google) = config.global_config.google.clone() { + google_robots = google.google_robots; + google_site_verification = google.google_site_verification; + } let map = hashmap!( "website_name".to_owned() => config.global_config.website.website_name, "page_title".to_owned() => config.page_config.page.title, + "page_description".to_owned() => config.page_config.page.description, "favicon".to_owned() => favicon.to_owned(), - "google_robots".to_owned() => google_robots, - "google_verification".to_owned() => google_verification, - "twitter_author".to_owned() => twitter_author, "before_navbar".to_owned() => before_navbar, "before_content".to_owned() => before_content, @@ -131,7 +128,21 @@ impl Template { "navbar".to_owned() => config.global_config.navbar.is_some().to_string(), "navbar_content".to_owned() => navbar_content, - "content".to_owned() => content + "content".to_owned() => content, + + "mobile_viewport".to_owned() => config.global_config.website.mobile_viewport.unwrap_or(true).to_string(), + "meta_description".to_owned() => config.global_config.website.meta_description.unwrap_or(true).to_string(), + "charset".to_owned() => config.global_config.website.charset.unwrap_or("utf-8".to_owned()), + "meta_og".to_owned() => config.global_config.website.meta_og.unwrap_or(true).to_string(), + + "twitter".to_owned() => config.global_config.twitter.is_some().to_string(), + "google".to_owned() => config.global_config.google.is_some().to_string(), + + "twitter_site".to_owned() => twitter_site, + "twitter_creator".to_owned() => twitter_creator, + + "google_robots".to_owned() => google_robots, + "google_site_verification".to_owned() => google_site_verification ); map diff --git a/src/templates/page-template.html b/src/templates/page-template.html index 8570ef1..27ba9bc 100644 --- a/src/templates/page-template.html +++ b/src/templates/page-template.html @@ -2,14 +2,13 @@ - - - - - - - + {{if mobile_viewport}} + {{endif}} {{if meta_description}} + {{endif}} + {{if google}} + + {{endif}} {{if meta_og}} @@ -18,13 +17,12 @@ - - - - + {{endif}} {{if twitter}} + + - {{if use_default_css}} + {{endif}} {{if use_default_css}} {{endif}} {{css_links}}{{javascript_links}}