-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add link_checker settings for external_level and internal_level (#1848)
* add external_level and internal_level * remove unnecessary debug derive on LinkDef * clarify doc comment about link check levels * simplify link checker logging * add missing warn prefix * simplify link level logging, remove "Level" from linklevel variants * remove link level config from test site * switch back to using bail! from get_link_domain * move console's deps to libs * remove unnecessary reference * calling console::error/warn directly * emit one error, or one warning, per link checker run * various link checker level changes * add docs about link checker levels * remove accidentally committed test site * remove completed TODO
- Loading branch information
Showing
23 changed files
with
357 additions
and
234 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub enum LinkCheckerLevel { | ||
#[serde(rename = "error")] | ||
Error, | ||
#[serde(rename = "warn")] | ||
Warn, | ||
} | ||
|
||
impl Default for LinkCheckerLevel { | ||
fn default() -> Self { | ||
Self::Error | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(default)] | ||
pub struct LinkChecker { | ||
/// Skip link checking for these URL prefixes | ||
pub skip_prefixes: Vec<String>, | ||
/// Skip anchor checking for these URL prefixes | ||
pub skip_anchor_prefixes: Vec<String>, | ||
/// Emit either "error" or "warn" for broken internal links (including anchor links). | ||
pub internal_level: LinkCheckerLevel, | ||
/// Emit either "error" or "warn" for broken external links (including anchor links). | ||
pub external_level: LinkCheckerLevel, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "console" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
errors = { path = "../errors" } | ||
libs = { path = "../libs" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::env; | ||
use std::io::Write; | ||
|
||
use libs::atty; | ||
use libs::once_cell::sync::Lazy; | ||
use libs::termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; | ||
|
||
/// Termcolor color choice. | ||
/// We do not rely on ColorChoice::Auto behavior | ||
/// as the check is already performed by has_color. | ||
static COLOR_CHOICE: Lazy<ColorChoice> = | ||
Lazy::new(|| if has_color() { ColorChoice::Always } else { ColorChoice::Never }); | ||
|
||
pub fn info(message: &str) { | ||
colorize(message, ColorSpec::new().set_bold(true), StandardStream::stdout(*COLOR_CHOICE)); | ||
} | ||
|
||
pub fn warn(message: &str) { | ||
colorize( | ||
&format!("{}{}", "Warning: ", message), | ||
ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow)), | ||
StandardStream::stdout(*COLOR_CHOICE), | ||
); | ||
} | ||
|
||
pub fn success(message: &str) { | ||
colorize( | ||
message, | ||
ColorSpec::new().set_bold(true).set_fg(Some(Color::Green)), | ||
StandardStream::stdout(*COLOR_CHOICE), | ||
); | ||
} | ||
|
||
pub fn error(message: &str) { | ||
colorize( | ||
&format!("{}{}", "Error: ", message), | ||
ColorSpec::new().set_bold(true).set_fg(Some(Color::Red)), | ||
StandardStream::stderr(*COLOR_CHOICE), | ||
); | ||
} | ||
|
||
/// Print a colorized message to stdout | ||
fn colorize(message: &str, color: &ColorSpec, mut stream: StandardStream) { | ||
stream.set_color(color).unwrap(); | ||
write!(stream, "{}", message).unwrap(); | ||
stream.set_color(&ColorSpec::new()).unwrap(); | ||
writeln!(stream).unwrap(); | ||
} | ||
|
||
/// Check whether to output colors | ||
fn has_color() -> bool { | ||
let use_colors = env::var("CLICOLOR").unwrap_or_else(|_| "1".to_string()) != "0" | ||
&& env::var("NO_COLOR").is_err(); | ||
let force_colors = env::var("CLICOLOR_FORCE").unwrap_or_else(|_| "0".to_string()) != "0"; | ||
|
||
force_colors || use_colors && atty::is(atty::Stream::Stdout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.