Fix some issues related to directory hierarchies

This commit is contained in:
Sofia 2018-04-16 18:04:28 +03:00
parent 510d744ccb
commit fe3a74a1c1
10 changed files with 52 additions and 27 deletions

View File

@ -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"
[navbar.item.other]
title = "Other"
link = "/other"

View File

@ -1,2 +0,0 @@
# Test Header!
Some test content!

View File

@ -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

View File

@ -10,7 +10,7 @@ use logger::LogLevel;
pub fn render_markdown_content(config: &SinglePageConfigs) -> Result<String, Error> {
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();

View File

@ -25,7 +25,7 @@
<meta name="twitter:title" content="{{page_title}}">
<meta name="twitter:description" content="{{page_description}}">
<meta name="twitter:image" content="{{favicon}}"> {{if use_default_css}}
<link rel="stylesheet" href="css/default.css"> {{endif}} {{css_links}}{{javascript_links}}
<link rel="stylesheet" href="/css/default.css"> {{endif}} {{css_links}}{{javascript_links}}
<link rel="shortcut icon" href="{{favicon}}"></link>

View File

@ -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"]

2
test_page/about.md Normal file
View File

@ -0,0 +1,2 @@
# About!
This is the test about for this page!

8
test_page/about.toml Normal file
View File

@ -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"]

2
test_page/other.md Normal file
View File

@ -0,0 +1,2 @@
# OTher
This page is not like the others

8
test_page/other.toml Normal file
View File

@ -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"]