Fix some warnings

This commit is contained in:
Sofia 2024-11-21 21:08:07 +02:00
parent 1d9aa7aca6
commit 8d7c446f4c
5 changed files with 27 additions and 41 deletions

View File

@ -1,18 +1,17 @@
use std::path::PathBuf;
use std::path::Path;
use std::fs::File;
use std::io::Read;
use std::error::Error as STDError;
use std::path::Path;
use std::path::PathBuf;
use pathdiff;
use crate::config::Config;
use crate::template::Template;
use crate::renderer;
use crate::logger::{LogLevel, Logger};
use crate::error::Error;
use crate::options::{BuildOpt, Opt};
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_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
logger.log(LogLevel::DETAILER, "Generating CSS tags");
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 {
let data = Template::css_tag_data_from(item, false);
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 {
let data = Template::css_tag_data_from(item, true);
css_string += &*css_tag_template.render(&data);
@ -104,14 +103,14 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
// Generate JS tags
logger.log(LogLevel::DETAILER, "Generating JS tags");
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 {
let data = Template::css_tag_data_from(item, false);
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 {
let data = Template::css_tag_data_from(item, true);
js_string += &*js_tag_template.render(&data);
@ -230,7 +229,7 @@ fn write_recursive_resource(
Ok(())
} else {
match File::open(resource_path.clone()) {
Ok(mut read_file) => {
Ok(read_file) => {
let bytes: Vec<u8> = match read_file.bytes().collect() {
Ok(bytes) => bytes,
Err(_) => Vec::new(),
@ -248,11 +247,7 @@ fn write_recursive_resource(
}
Err(err) => Err(Error::new(
LogLevel::SEVERE,
format!(
"Failed to open read file {:?}: {}",
resource_path,
err.description().to_owned()
),
format!("Failed to open read file {:?}: {}", resource_path, err),
)),
}
}

View File

@ -1,6 +1,5 @@
use std::convert::From;
use std::io::Error as IOError;
use std::error::Error as STDError;
use crate::logger::LogLevel;
@ -34,7 +33,7 @@ impl From<IOError> for Error {
os_error = format!("OS Error: {}", error);
}
Error {
description: format!("IOError: {} {}", err.description().to_owned(), os_error),
description: format!("IOError: {} {}", err, os_error),
severity: LogLevel::SEVERE,
}
}

View File

@ -1,10 +1,9 @@
use std::fs::{create_dir_all, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::error::Error as STDError;
use serde::Serialize;
use serde::de::DeserializeOwned;
use serde::Serialize;
use toml;
use crate::error::Error;
@ -27,7 +26,7 @@ pub fn get_toml<T: DeserializeOwned>(path: &PathBuf) -> Result<T, Error> {
format!(
"Failed to open toml: {}, Reason: {}",
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(
LogLevel::SEVERE,
format!(
"Failed to serialize {:?}: {}",
path,
err.description().to_owned()
),
format!("Failed to serialize {:?}: {}", path, err),
)),
}
}
@ -89,7 +84,7 @@ pub fn write_file<T: Into<String>>(
pub fn write_bytes(path: &PathBuf, bytes: &[u8], overwrite: bool) -> Result<(), Error> {
if let Some(parent) = path.clone().parent() {
create_dir_all(parent.clone())?;
create_dir_all(parent)?;
} else {
return Err(Error::new(
LogLevel::SEVERE,

View File

@ -1,15 +1,14 @@
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::error::Error;
use crate::file_writer;
use crate::logger::{LogLevel, Logger};
use crate::options::{NewOpt, Opt};
use pathdiff;
const PLACEHOLDER_MARKDOWN: &'static str =
r#"# Placeholder title
const PLACEHOLDER_MARKDOWN: &'static str = r#"# Placeholder title
This is the markdown file, where you will insert this page's contents.
- This is an example list
- 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()) {
let mut filename = file_name.to_str().unwrap().to_owned();
let clone = filename.clone();
let mut split = clone.split(".");
let split = clone.split(".");
if split.clone().count() == 1 as usize {
path = parent.join(format!("{}.{}", filename, extension));
} else if replace_extension {

View File

@ -1,16 +1,15 @@
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::error::Error as STDError;
use pulldown_cmark::{html, Parser};
use regex::{Captures, Regex};
use crate::config::{Config, SinglePageConfigs};
use crate::template::Template;
use crate::config_toml::InjectionToml;
use crate::error::Error;
use crate::logger::{LogLevel, Logger};
use crate::config_toml::InjectionToml;
use crate::template::Template;
fn get_file_contents(path: Option<String>) -> Result<String, Error> {
match path {
@ -22,7 +21,7 @@ fn get_file_contents(path: Option<String>) -> Result<String, Error> {
}
Err(err) => Err(Error::new(
LogLevel::WARNING,
format!("Failed to open {}, {}", url, err.description().to_owned()),
format!("Failed to open {}, {}", url, err),
)),
},
None => Ok(String::new()),
@ -193,8 +192,7 @@ fn replace(config: InjectionToml) -> String {
}
Err(err) => format!(
"Failed to get template for custom markdown: {}, {}",
config.meta.template,
err.description().to_owned(),
config.meta.template, err,
),
}
}