diff --git a/components/markdown/src/markdown.rs b/components/markdown/src/markdown.rs index 8d4393358c..4eb10f331e 100644 --- a/components/markdown/src/markdown.rs +++ b/components/markdown/src/markdown.rs @@ -1,12 +1,13 @@ use std::fmt::Write; +use errors::bail; use libs::gh_emoji::Replacer as EmojiReplacer; use libs::once_cell::sync::Lazy; use libs::pulldown_cmark as cmark; use libs::tera; use crate::context::RenderContext; -use errors::{anyhow, Context, Error, Result}; +use errors::{Context, Error, Result}; use libs::pulldown_cmark::escape::escape_html; use utils::site::resolve_internal_link; use utils::slugs::slugify_anchors; @@ -140,14 +141,14 @@ fn fix_link( } Err(_) => { let msg = format!( - "Dead relative link `{}` in {}", + "Broken relative link `{}` in {}", link, context.current_page_path.unwrap_or("unknown"), ); match context.config.link_checker.internal_level { - config::LinkCheckerLevel::Error => return Err(anyhow!(msg)), + config::LinkCheckerLevel::Error => bail!(msg), config::LinkCheckerLevel::Warn => { - console::error(&msg); + console::warn(&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/lib.rs b/components/site/src/lib.rs index f1f59b6c98..6615bfceb7 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -6,7 +6,6 @@ pub mod sitemap; pub mod tpls; use std::collections::HashMap; -use std::fmt::format; use std::fs::remove_dir_all; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, RwLock}; @@ -306,7 +305,7 @@ impl Site { .map(|(i, msg)| format!(" {}. {}", i + 1, msg)) .collect(); let msg = format!( - "Found {} broken internal anchor links\n{}", + "Found {} broken internal anchor link(s)\n{}", messages.len(), messages.join("\n") ); @@ -326,7 +325,7 @@ impl Site { .map(|(i, msg)| format!(" {}. {}", i + 1, msg)) .collect(); let msg = format!( - "Found {} broken external links\n{}", + "Found {} broken external link(s)\n{}", messages.len(), messages.join("\n") ); diff --git a/components/site/src/link_checking.rs b/components/site/src/link_checking.rs index 81e5b082fa..589927d8ef 100644 --- a/components/site/src/link_checking.rs +++ b/components/site/src/link_checking.rs @@ -4,7 +4,7 @@ use std::{collections::HashMap, path::PathBuf, thread}; use config::LinkCheckerLevel; use libs::rayon::prelude::*; -use crate::{anyhow, Site}; +use crate::Site; use errors::{bail, Result}; use libs::rayon; use libs::url::Url; @@ -173,14 +173,15 @@ pub fn check_external_links(site: &Site) -> Result<(), Vec> { } ); - if !invalid_url_links.is_empty() { - for err in invalid_url_links.into_iter() { - let msg = err.domain.as_ref().unwrap_err(); - match site.config.link_checker.internal_level { - LinkCheckerLevel::Error => console::error(&msg.to_string()), - LinkCheckerLevel::Warn => console::warn(&msg.to_string()), - } - } + for err in invalid_url_links.into_iter() { + let msg = err.domain.as_ref().unwrap_err().to_string(); + messages.push(msg); + } + + // error out if we're in error mode and any external URLs couldn't be parsed + match site.config.link_checker.external_level { + LinkCheckerLevel::Error if messages.len() > 0 => return Err(messages), + _ => (), } let mut links_by_domain: HashMap> = HashMap::new(); @@ -248,7 +249,7 @@ pub fn check_external_links(site: &Site) -> Result<(), Vec> { for (page_path, link, check_res) in errors.iter() { messages.push(format!( - "Dead link in {} to {}: {}", + "Broken link in {} to {}: {}", page_path.to_string_lossy(), link, link_checker::message(check_res) @@ -258,10 +259,5 @@ pub fn check_external_links(site: &Site) -> Result<(), Vec> { Err(pool_err) => messages.push(pool_err.to_string()), } - // match site.config.link_checker.external_level { - // LinkCheckerLevel::Error => Err(anyhow!("Dead links found")), - // LinkCheckerLevel::Warn => Ok(()), - // } - Err(messages) } diff --git a/link-checker-level-test/config.toml b/link-checker-level-test/config.toml index 67fc3b74e3..c5b6ca47f7 100644 --- a/link-checker-level-test/config.toml +++ b/link-checker-level-test/config.toml @@ -16,5 +16,5 @@ highlight_code = false # Put all your custom variables here [link_checker] -internal_level = "error" -external_level = "error" +internal_level = "warn" +external_level = "warn" diff --git a/link-checker-level-test/content/post.md b/link-checker-level-test/content/post.md index c0c2ba34b6..5f8e8505c8 100644 --- a/link-checker-level-test/content/post.md +++ b/link-checker-level-test/content/post.md @@ -3,11 +3,10 @@ template = "single.html" +++ [good internal link](./) -[no DNS external link](https://sddfsdjf.com) -[404 external link](https://clayto.com/1234) -[invalid domain external link](https://clabad anchor link 1 +

good internal link +bad anchor link 1 bad anchor link 2 -bad anchor link 3 -good internal link -no DNS external link -404 external link -invalid domain external link -invalid domain external link -invalid domain external link -invalid domain external link -invalid domain external link -invalid domain external link

+bad internal link 1 +bad internal link 2 +invalid domain external link 1 +invalid domain external link 2

+