From fe3a74a1c11c9d36845b8511a266c5b30d86724c Mon Sep 17 00:00:00 2001 From: Teascade Date: Mon, 16 Apr 2018 18:04:28 +0300 Subject: [PATCH] Fix some issues related to directory hierarchies --- config.toml | 17 ++++++++--------- content.md | 2 -- src/config_toml.rs | 28 ++++++++++++++++++++++------ src/renderer.rs | 2 +- src/templates/page-template.html | 2 +- test_page.toml | 8 -------- test_page/about.md | 2 ++ test_page/about.toml | 8 ++++++++ test_page/other.md | 2 ++ test_page/other.toml | 8 ++++++++ 10 files changed, 52 insertions(+), 27 deletions(-) delete mode 100644 content.md delete mode 100644 test_page.toml create mode 100644 test_page/about.md create mode 100644 test_page/about.toml create mode 100644 test_page/other.md create mode 100644 test_page/other.toml diff --git a/config.toml b/config.toml index 11df64b..eda963e 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ [website] website_name = "Test Website Name!" -built_pages = ["test_page.toml"] +built_pages = ["test_page/about.toml", "test_page/other.toml"] use_default_css = true javascript = [] css = [] @@ -10,13 +10,12 @@ css = [] #google_site_verification = "" [navbar] -items = ["home", "games"] +items = ["about", "other"] - [navbar.item.home] - title = "Home" - link = "home" - image_url = "img/teascade.png" + [navbar.item.about] + title = "About" + link = "/" - [navbar.item.games] - title = "Games" - link = "/games" \ No newline at end of file + [navbar.item.other] + title = "Other" + link = "/other" \ No newline at end of file diff --git a/content.md b/content.md deleted file mode 100644 index 2e85b51..0000000 --- a/content.md +++ /dev/null @@ -1,2 +0,0 @@ -# Test Header! -Some test content! \ No newline at end of file diff --git a/src/config_toml.rs b/src/config_toml.rs index 3826be4..cc6e6fe 100644 --- a/src/config_toml.rs +++ b/src/config_toml.rs @@ -2,9 +2,13 @@ use toml; use std::path::PathBuf; use std::fs::File; -use std::io::{Error, ErrorKind, Read}; +use std::io::{Error as IOError, ErrorKind, Read}; +use std::error::Error as STDError; use std::collections::HashMap; +use logger::LogLevel; +use error::Error; + #[derive(Deserialize, Clone, Debug)] pub struct GlobalConfigToml { pub website: WebsiteConfig, @@ -48,12 +52,12 @@ impl GlobalConfigToml { Err(err) => { if let Some((line, col)) = err.line_col() { Err(Error::new( - ErrorKind::Other, + LogLevel::SEVERE, format!("Erronous config.toml at {}:{}", line, col), )) } else { Err(Error::new( - ErrorKind::Other, + LogLevel::SEVERE, format!("Failed to parse config.toml correctly. Check variable names!"), )) } @@ -74,7 +78,19 @@ impl PageConfigToml { None => "", }; - let mut file = File::open(path.as_path())?; + let mut file = match File::open(path.as_path()) { + Ok(file) => file, + Err(err) => { + return Err(Error::new( + LogLevel::SEVERE, + format!( + "Failed to open page config: {}, Reason: {}", + path.to_str().unwrap(), + err.description().to_owned() + ), + )) + } + }; let mut contents = String::new(); file.read_to_string(&mut contents)?; match toml::from_str(&contents) { @@ -82,12 +98,12 @@ impl PageConfigToml { Err(err) => { if let Some((line, col)) = err.line_col() { Err(Error::new( - ErrorKind::Other, + LogLevel::SEVERE, format!("Erronous toml: {} at {}:{}", path_str, line, col), )) } else { Err(Error::new( - ErrorKind::Other, + LogLevel::SEVERE, format!( "Failed to parse toml correctly: {}. Check variable names!", path_str diff --git a/src/renderer.rs b/src/renderer.rs index b6e6712..5ceffd3 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -10,7 +10,7 @@ use logger::LogLevel; pub fn render_markdown_content(config: &SinglePageConfigs) -> Result { if let Some(parent) = config.page_config_path.parent() { - let path = parent.with_file_name(&config.page_config.page.content_path); + let path = parent.join(&config.page_config.page.content_path); match File::open(&path) { Ok(mut file) => { let mut content = String::new(); diff --git a/src/templates/page-template.html b/src/templates/page-template.html index 7726665..828c924 100644 --- a/src/templates/page-template.html +++ b/src/templates/page-template.html @@ -25,7 +25,7 @@ {{if use_default_css}} - {{endif}} {{css_links}}{{javascript_links}} + {{endif}} {{css_links}}{{javascript_links}} diff --git a/test_page.toml b/test_page.toml deleted file mode 100644 index 953a0d3..0000000 --- a/test_page.toml +++ /dev/null @@ -1,8 +0,0 @@ -[page] -html_path = "test.html" -title = "Test Page" -description = "This is a test page." -content_path = "content.md" -#favicon = "optional_favicon.png" -#javascript = ["Additional JavaScript"] -#css = ["Additional CSS"] \ No newline at end of file diff --git a/test_page/about.md b/test_page/about.md new file mode 100644 index 0000000..c35565e --- /dev/null +++ b/test_page/about.md @@ -0,0 +1,2 @@ +# About! +This is the test about for this page! \ No newline at end of file diff --git a/test_page/about.toml b/test_page/about.toml new file mode 100644 index 0000000..dc860d2 --- /dev/null +++ b/test_page/about.toml @@ -0,0 +1,8 @@ +[page] +html_path = "index.html" +title = "About" +description = "This is the test About page" +content_path = "about.md" +favicon = "/favicon.png" +#javascript = ["Additional JavaScript"] +#css = ["Additional CSS"] \ No newline at end of file diff --git a/test_page/other.md b/test_page/other.md new file mode 100644 index 0000000..a979280 --- /dev/null +++ b/test_page/other.md @@ -0,0 +1,2 @@ +# OTher +This page is not like the others \ No newline at end of file diff --git a/test_page/other.toml b/test_page/other.toml new file mode 100644 index 0000000..81a84eb --- /dev/null +++ b/test_page/other.toml @@ -0,0 +1,8 @@ +[page] +html_path = "other/index.html" +title = "Other!" +description = "This is the .. other page" +content_path = "other.md" +#favicon = "optional_favicon.png" +#javascript = ["Additional JavaScript"] +#css = ["Additional CSS"] \ No newline at end of file