Fix some warnings
This commit is contained in:
parent
1d9aa7aca6
commit
8d7c446f4c
@ -1,18 +1,17 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::error::Error as STDError;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use pathdiff;
|
use pathdiff;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::template::Template;
|
|
||||||
use crate::renderer;
|
|
||||||
use crate::logger::{LogLevel, Logger};
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::options::{BuildOpt, Opt};
|
|
||||||
use crate::file_writer;
|
use crate::file_writer;
|
||||||
|
use crate::logger::{LogLevel, Logger};
|
||||||
|
use crate::options::{BuildOpt, Opt};
|
||||||
|
use crate::renderer;
|
||||||
|
use crate::template::Template;
|
||||||
|
|
||||||
const DEFAULT_CSS: &'static str = include_str!("templates/default-css.css");
|
const DEFAULT_CSS: &'static str = include_str!("templates/default-css.css");
|
||||||
const DEFAULT_JS: &'static str = include_str!("templates/default-js.js");
|
const DEFAULT_JS: &'static str = include_str!("templates/default-js.js");
|
||||||
@ -87,14 +86,14 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
// Generate CSS tagstags
|
// Generate CSS tagstags
|
||||||
logger.log(LogLevel::DETAILER, "Generating CSS tags");
|
logger.log(LogLevel::DETAILER, "Generating CSS tags");
|
||||||
let mut css_string = String::new();
|
let mut css_string = String::new();
|
||||||
let mut css_list = config.global_config.website.css.clone();
|
let css_list = config.global_config.website.css.clone();
|
||||||
|
|
||||||
for item in css_list {
|
for item in css_list {
|
||||||
let data = Template::css_tag_data_from(item, false);
|
let data = Template::css_tag_data_from(item, false);
|
||||||
css_string += &*css_tag_template.render(&data);
|
css_string += &*css_tag_template.render(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mut list) = config.page_config.page.css.clone() {
|
if let Some(list) = config.page_config.page.css.clone() {
|
||||||
for item in list {
|
for item in list {
|
||||||
let data = Template::css_tag_data_from(item, true);
|
let data = Template::css_tag_data_from(item, true);
|
||||||
css_string += &*css_tag_template.render(&data);
|
css_string += &*css_tag_template.render(&data);
|
||||||
@ -104,14 +103,14 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
// Generate JS tags
|
// Generate JS tags
|
||||||
logger.log(LogLevel::DETAILER, "Generating JS tags");
|
logger.log(LogLevel::DETAILER, "Generating JS tags");
|
||||||
let mut js_string = String::new();
|
let mut js_string = String::new();
|
||||||
let mut js_list = config.global_config.website.javascript.clone();
|
let js_list = config.global_config.website.javascript.clone();
|
||||||
|
|
||||||
for item in js_list {
|
for item in js_list {
|
||||||
let data = Template::css_tag_data_from(item, false);
|
let data = Template::css_tag_data_from(item, false);
|
||||||
js_string += &*js_tag_template.render(&data);
|
js_string += &*js_tag_template.render(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mut list) = config.page_config.page.javascript.clone() {
|
if let Some(list) = config.page_config.page.javascript.clone() {
|
||||||
for item in list {
|
for item in list {
|
||||||
let data = Template::css_tag_data_from(item, true);
|
let data = Template::css_tag_data_from(item, true);
|
||||||
js_string += &*js_tag_template.render(&data);
|
js_string += &*js_tag_template.render(&data);
|
||||||
@ -230,7 +229,7 @@ fn write_recursive_resource(
|
|||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
match File::open(resource_path.clone()) {
|
match File::open(resource_path.clone()) {
|
||||||
Ok(mut read_file) => {
|
Ok(read_file) => {
|
||||||
let bytes: Vec<u8> = match read_file.bytes().collect() {
|
let bytes: Vec<u8> = match read_file.bytes().collect() {
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(_) => Vec::new(),
|
Err(_) => Vec::new(),
|
||||||
@ -248,11 +247,7 @@ fn write_recursive_resource(
|
|||||||
}
|
}
|
||||||
Err(err) => Err(Error::new(
|
Err(err) => Err(Error::new(
|
||||||
LogLevel::SEVERE,
|
LogLevel::SEVERE,
|
||||||
format!(
|
format!("Failed to open read file {:?}: {}", resource_path, err),
|
||||||
"Failed to open read file {:?}: {}",
|
|
||||||
resource_path,
|
|
||||||
err.description().to_owned()
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
use std::error::Error as STDError;
|
|
||||||
|
|
||||||
use crate::logger::LogLevel;
|
use crate::logger::LogLevel;
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ impl From<IOError> for Error {
|
|||||||
os_error = format!("OS Error: {}", error);
|
os_error = format!("OS Error: {}", error);
|
||||||
}
|
}
|
||||||
Error {
|
Error {
|
||||||
description: format!("IOError: {} {}", err.description().to_owned(), os_error),
|
description: format!("IOError: {} {}", err, os_error),
|
||||||
severity: LogLevel::SEVERE,
|
severity: LogLevel::SEVERE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use std::fs::{create_dir_all, File};
|
use std::fs::{create_dir_all, File};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::error::Error as STDError;
|
|
||||||
|
|
||||||
use serde::Serialize;
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use serde::Serialize;
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
@ -27,7 +26,7 @@ pub fn get_toml<T: DeserializeOwned>(path: &PathBuf) -> Result<T, Error> {
|
|||||||
format!(
|
format!(
|
||||||
"Failed to open toml: {}, Reason: {}",
|
"Failed to open toml: {}, Reason: {}",
|
||||||
path.to_str().unwrap(),
|
path.to_str().unwrap(),
|
||||||
err.description().to_owned()
|
err
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -70,11 +69,7 @@ pub fn write_toml<T: Serialize>(path: &PathBuf, data: &T, overwrite: bool) -> Re
|
|||||||
},
|
},
|
||||||
Err(err) => Err(Error::new(
|
Err(err) => Err(Error::new(
|
||||||
LogLevel::SEVERE,
|
LogLevel::SEVERE,
|
||||||
format!(
|
format!("Failed to serialize {:?}: {}", path, err),
|
||||||
"Failed to serialize {:?}: {}",
|
|
||||||
path,
|
|
||||||
err.description().to_owned()
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +84,7 @@ pub fn write_file<T: Into<String>>(
|
|||||||
|
|
||||||
pub fn write_bytes(path: &PathBuf, bytes: &[u8], overwrite: bool) -> Result<(), Error> {
|
pub fn write_bytes(path: &PathBuf, bytes: &[u8], overwrite: bool) -> Result<(), Error> {
|
||||||
if let Some(parent) = path.clone().parent() {
|
if let Some(parent) = path.clone().parent() {
|
||||||
create_dir_all(parent.clone())?;
|
create_dir_all(parent)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
LogLevel::SEVERE,
|
LogLevel::SEVERE,
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::options::{NewOpt, Opt};
|
|
||||||
use crate::logger::{LogLevel, Logger};
|
|
||||||
use crate::file_writer;
|
|
||||||
use crate::error::Error;
|
|
||||||
use crate::config_toml::{GlobalConfigToml, PageConfig, PageConfigToml};
|
use crate::config_toml::{GlobalConfigToml, PageConfig, PageConfigToml};
|
||||||
|
use crate::error::Error;
|
||||||
|
use crate::file_writer;
|
||||||
|
use crate::logger::{LogLevel, Logger};
|
||||||
|
use crate::options::{NewOpt, Opt};
|
||||||
|
|
||||||
use pathdiff;
|
use pathdiff;
|
||||||
|
|
||||||
const PLACEHOLDER_MARKDOWN: &'static str =
|
const PLACEHOLDER_MARKDOWN: &'static str = r#"# Placeholder title
|
||||||
r#"# Placeholder title
|
|
||||||
This is the markdown file, where you will insert this page's contents.
|
This is the markdown file, where you will insert this page's contents.
|
||||||
- This is an example list
|
- This is an example list
|
||||||
- And in lists
|
- And in lists
|
||||||
@ -151,7 +150,7 @@ fn ensure_extension<T: Into<String>>(
|
|||||||
if let (Some(parent), Some(file_name)) = (path.clone().parent(), path.clone().file_name()) {
|
if let (Some(parent), Some(file_name)) = (path.clone().parent(), path.clone().file_name()) {
|
||||||
let mut filename = file_name.to_str().unwrap().to_owned();
|
let mut filename = file_name.to_str().unwrap().to_owned();
|
||||||
let clone = filename.clone();
|
let clone = filename.clone();
|
||||||
let mut split = clone.split(".");
|
let split = clone.split(".");
|
||||||
if split.clone().count() == 1 as usize {
|
if split.clone().count() == 1 as usize {
|
||||||
path = parent.join(format!("{}.{}", filename, extension));
|
path = parent.join(format!("{}.{}", filename, extension));
|
||||||
} else if replace_extension {
|
} else if replace_extension {
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::error::Error as STDError;
|
|
||||||
|
|
||||||
use pulldown_cmark::{html, Parser};
|
use pulldown_cmark::{html, Parser};
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
|
|
||||||
use crate::config::{Config, SinglePageConfigs};
|
use crate::config::{Config, SinglePageConfigs};
|
||||||
use crate::template::Template;
|
use crate::config_toml::InjectionToml;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::logger::{LogLevel, Logger};
|
use crate::logger::{LogLevel, Logger};
|
||||||
use crate::config_toml::InjectionToml;
|
use crate::template::Template;
|
||||||
|
|
||||||
fn get_file_contents(path: Option<String>) -> Result<String, Error> {
|
fn get_file_contents(path: Option<String>) -> Result<String, Error> {
|
||||||
match path {
|
match path {
|
||||||
@ -22,7 +21,7 @@ fn get_file_contents(path: Option<String>) -> Result<String, Error> {
|
|||||||
}
|
}
|
||||||
Err(err) => Err(Error::new(
|
Err(err) => Err(Error::new(
|
||||||
LogLevel::WARNING,
|
LogLevel::WARNING,
|
||||||
format!("Failed to open {}, {}", url, err.description().to_owned()),
|
format!("Failed to open {}, {}", url, err),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
None => Ok(String::new()),
|
None => Ok(String::new()),
|
||||||
@ -193,8 +192,7 @@ fn replace(config: InjectionToml) -> String {
|
|||||||
}
|
}
|
||||||
Err(err) => format!(
|
Err(err) => format!(
|
||||||
"Failed to get template for custom markdown: {}, {}",
|
"Failed to get template for custom markdown: {}, {}",
|
||||||
config.meta.template,
|
config.meta.template, err,
|
||||||
err.description().to_owned(),
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user