From 933189b7b2889109f5a0762916e8ad1453216804 Mon Sep 17 00:00:00 2001 From: Teascade Date: Mon, 16 Apr 2018 18:22:13 +0300 Subject: [PATCH] Add before/after navbar/content and make navbar not render when needed --- config.toml | 23 +++++++++++++++-------- src/config_toml.rs | 8 +++++++- src/template.rs | 2 +- src/templates/page-template.html | 5 +++-- test_page/about.toml | 3 +++ test_page/other.toml | 3 +++ 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/config.toml b/config.toml index eda963e..3557bef 100644 --- a/config.toml +++ b/config.toml @@ -4,18 +4,25 @@ built_pages = ["test_page/about.toml", "test_page/other.toml"] use_default_css = true javascript = [] css = [] +#before_navbar_url = "/navbar.html" +#before_content_url = "/before_content.html" +#after_content_url = "/after_content.html" #favicon = "favicon.png" #twitter_author = "@teascade" #google_robots = "all" #google_site_verification = "" -[navbar] -items = ["about", "other"] +#[navbar] +#items = ["about", "other", "google"] - [navbar.item.about] - title = "About" - link = "/" +# [navbar.item.about] +# title = "About" +# link = "/" - [navbar.item.other] - title = "Other" - link = "/other" \ No newline at end of file +# [navbar.item.other] +# title = "Other" +# link = "/other" + +# [navbar.item.google] +# title = "Google!" +# link = "https://google.com" \ No newline at end of file diff --git a/src/config_toml.rs b/src/config_toml.rs index cc6e6fe..a5a17dd 100644 --- a/src/config_toml.rs +++ b/src/config_toml.rs @@ -2,7 +2,7 @@ use toml; use std::path::PathBuf; use std::fs::File; -use std::io::{Error as IOError, ErrorKind, Read}; +use std::io::Read; use std::error::Error as STDError; use std::collections::HashMap; @@ -23,6 +23,9 @@ pub struct WebsiteConfig { 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, @@ -122,6 +125,9 @@ pub struct PageConfig { pub description: String, pub content_path: String, pub favicon: Option, + pub before_navbar_url: Option, + pub before_content_url: Option, + pub after_content_url: Option, pub javascript: Option>, pub css: Option>, } diff --git a/src/template.rs b/src/template.rs index 5e726bf..f2c560c 100644 --- a/src/template.rs +++ b/src/template.rs @@ -110,7 +110,7 @@ impl Template { "twitter_author".to_owned() => twitter_author, "use_default_css".to_owned() => config.global_config.website.use_default_css.to_string(), - "navbar".to_owned() => "true".to_owned(), + "navbar".to_owned() => config.global_config.navbar.is_some().to_string(), "navbar_content".to_owned() => navbar_content, "content".to_owned() => content diff --git a/src/templates/page-template.html b/src/templates/page-template.html index 828c924..8570ef1 100644 --- a/src/templates/page-template.html +++ b/src/templates/page-template.html @@ -33,16 +33,17 @@ - {{if navbar}} + {{before_navbar}} {{if navbar}} - {{endif}} + {{endif}} {{before_content}}
{{content}}
+ {{after_content}} \ No newline at end of file diff --git a/test_page/about.toml b/test_page/about.toml index dc860d2..fd7d8c8 100644 --- a/test_page/about.toml +++ b/test_page/about.toml @@ -4,5 +4,8 @@ title = "About" description = "This is the test About page" content_path = "about.md" favicon = "/favicon.png" +#before_navbar_url = "/navbar.html" +#before_content_url = "/before_content.html" +#after_content_url = "/after_content.html" #javascript = ["Additional JavaScript"] #css = ["Additional CSS"] \ No newline at end of file diff --git a/test_page/other.toml b/test_page/other.toml index 81a84eb..30cd7e6 100644 --- a/test_page/other.toml +++ b/test_page/other.toml @@ -4,5 +4,8 @@ title = "Other!" description = "This is the .. other page" content_path = "other.md" #favicon = "optional_favicon.png" +#before_navbar_url = "/navbar.html" +#before_content_url = "/before_content.html" +#after_content_url = "/after_content.html" #javascript = ["Additional JavaScript"] #css = ["Additional CSS"] \ No newline at end of file