diff --git a/Cargo.lock b/Cargo.lock index 97a1dc4a1b..01c811fa8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,7 +371,6 @@ dependencies = [ name = "config" version = "0.1.0" dependencies = [ - "console 0.1.0", "errors", "libs", "serde", diff --git a/components/config/Cargo.toml b/components/config/Cargo.toml index d84ed076ba..d7ef4029b6 100644 --- a/components/config/Cargo.toml +++ b/components/config/Cargo.toml @@ -7,7 +7,6 @@ include = ["src/**/*"] [dependencies] serde = {version = "1.0", features = ["derive"] } -console = { path = "../console" } errors = { path = "../errors" } utils = { path = "../utils" } libs = { path = "../libs" } diff --git a/components/config/src/config/link_checker.rs b/components/config/src/config/link_checker.rs index 5af095bfc3..8501287981 100644 --- a/components/config/src/config/link_checker.rs +++ b/components/config/src/config/link_checker.rs @@ -1,4 +1,3 @@ -use console; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -15,25 +14,6 @@ impl Default for LinkCheckerLevel { } } -impl LinkCheckerLevel { - pub fn log(&self, msg: String) { - match self { - LinkCheckerLevel::Error => { - console::error(format!("{}{}", self.log_prefix(), msg).as_str()) - } - LinkCheckerLevel::Warn => { - console::warn(format!("{}{}", self.log_prefix(), msg).as_str()) - } - } - } - pub fn log_prefix(&self) -> &str { - match self { - LinkCheckerLevel::Error => "Error: ", - LinkCheckerLevel::Warn => "Warning: ", - } - } -} - #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] pub struct LinkChecker { diff --git a/components/console/src/lib.rs b/components/console/src/lib.rs index e700057c3c..e480c8f3f9 100644 --- a/components/console/src/lib.rs +++ b/components/console/src/lib.rs @@ -17,7 +17,7 @@ pub fn info(message: &str) { pub fn warn(message: &str) { colorize( - message, + &format!("{}{}", "Warning: ", message), ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow)), StandardStream::stdout(*COLOR_CHOICE), ); @@ -33,7 +33,7 @@ pub fn success(message: &str) { pub fn error(message: &str) { colorize( - message, + &format!("{}{}", "Error: ", message), ColorSpec::new().set_bold(true).set_fg(Some(Color::Red)), StandardStream::stderr(*COLOR_CHOICE), ); diff --git a/components/markdown/src/markdown.rs b/components/markdown/src/markdown.rs index f35c9827fa..8d4393358c 100644 --- a/components/markdown/src/markdown.rs +++ b/components/markdown/src/markdown.rs @@ -139,30 +139,16 @@ fn fix_link( resolved.permalink } Err(_) => { - context.config.link_checker.internal_level.log(format!( + let msg = format!( "Dead relative link `{}` in {}", link, context.current_page_path.unwrap_or("unknown"), - )); + ); match context.config.link_checker.internal_level { - config::LinkCheckerLevel::Error => { - return Err(anyhow!( - "Dead relative link `{}` in {}", - link, - context.current_page_path.unwrap_or("unknown"), - )) - } + config::LinkCheckerLevel::Error => return Err(anyhow!(msg)), config::LinkCheckerLevel::Warn => { - console::warn( - format!( - "{}Dead relative link `{}` in {}", - config::LinkCheckerLevel::Warn.log_prefix(), - link, - context.current_page_path.unwrap_or("unknown"), - ) - .as_str(), - ); - link.to_string() // TODO rendering the broken internal relative link may not be optimal, what href should be rendered to HTML when relative links are invalid but we're in warn mode? + console::error(&msg); + link.to_string() // TODO document that broken internal relative links will show up in the HTML href as "@/path" } } } diff --git a/components/site/src/link_checking.rs b/components/site/src/link_checking.rs index e0fd65671d..4cd547e083 100644 --- a/components/site/src/link_checking.rs +++ b/components/site/src/link_checking.rs @@ -100,7 +100,10 @@ pub fn check_internal_links_with_anchors(site: &Site) -> Result<()> { ); for err in errors.into_iter() { - site.config.link_checker.internal_level.log(err); + match site.config.link_checker.internal_level { + LinkCheckerLevel::Error => console::error(&err), + LinkCheckerLevel::Warn => console::warn(&err), + } } match site.config.link_checker.internal_level { @@ -183,7 +186,10 @@ pub fn check_external_links(site: &Site) -> Result<()> { if !invalid_url_links.is_empty() { for err in invalid_url_links.into_iter() { let msg = err.domain.as_ref().unwrap_err(); - site.config.link_checker.external_level.log(msg.to_string()); + match site.config.link_checker.internal_level { + LinkCheckerLevel::Error => console::error(&msg.to_string()), + LinkCheckerLevel::Warn => console::warn(&msg.to_string()), + } } } @@ -249,12 +255,17 @@ pub fn check_external_links(site: &Site) -> Result<()> { } for (page_path, link, check_res) in errors.iter() { - site.config.link_checker.external_level.log(format!( + let msg = format!( "Dead link in {} to {}: {}", page_path.to_string_lossy(), link, link_checker::message(check_res) - )); + ); + + match site.config.link_checker.external_level { + LinkCheckerLevel::Error => todo!(), + LinkCheckerLevel::Warn => todo!(), + } } match site.config.link_checker.external_level {