From e6771dccc21a31c83b45ecc3f00b92361c191ee3 Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Tue, 29 Oct 2024 09:21:29 +0100 Subject: [PATCH] chore(build): don't add inline (data) issues --- crates/rari-cli/main.rs | 4 +++ crates/rari-doc/src/html/rewriter.rs | 48 ++++++++++++++++++++-------- crates/rari-types/src/settings.rs | 1 + 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/crates/rari-cli/main.rs b/crates/rari-cli/main.rs index 3c9a214b..d1dc606a 100644 --- a/crates/rari-cli/main.rs +++ b/crates/rari-cli/main.rs @@ -145,6 +145,8 @@ struct BuildArgs { templ_stats: bool, #[arg(long)] issues: Option, + #[arg(long)] + data_issues: bool, } enum Cache { @@ -187,6 +189,7 @@ fn main() -> Result<(), Error> { let mut settings = Settings::new()?; settings.deny_warnings = args.deny_warnings; settings.cache_content = args.cache_content; + settings.data_issues = args.data_issues; let _ = SETTINGS.set(settings); let templ_stats = if args.templ_stats { @@ -340,6 +343,7 @@ fn main() -> Result<(), Error> { let mut settings = Settings::new()?; settings.deny_warnings = args.deny_warnings; settings.cache_content = args.cache_content; + settings.data_issues = true; let _ = SETTINGS.set(settings); serve::serve(memory_layer.clone())? } diff --git a/crates/rari-doc/src/html/rewriter.rs b/crates/rari-doc/src/html/rewriter.rs index fd41d0fb..9604b0af 100644 --- a/crates/rari-doc/src/html/rewriter.rs +++ b/crates/rari-doc/src/html/rewriter.rs @@ -6,6 +6,7 @@ use lol_html::{element, rewrite_str, HtmlRewriter, RewriteStrSettings, Settings} use rari_md::ext::DELIM_START; use rari_md::node_card::NoteCard; use rari_types::fm_types::PageType; +use rari_types::globals::settings; use rari_types::locale::Locale; use rari_utils::concat_strs; use tracing::warn; @@ -51,6 +52,7 @@ pub fn post_process_html( if url.ends_with('/') { "" } else { "/" } ))?; let base_url = options.base_url(Some(&base)); + let data_issues = settings().data_issues; let mut element_content_handlers = vec![ element!("*[id]", |el| { @@ -110,7 +112,9 @@ pub fn post_process_html( "Error parsing {}: {e}", file.display() ); - el.set_attribute("data-flaw", &ic.to_string())?; + if data_issues { + el.set_attribute("data-flaw", &ic.to_string())?; + } (None, None) } } @@ -125,7 +129,9 @@ pub fn post_process_html( "Error opening {}: {e}", file.display() ); - el.set_attribute("data-flaw", &ic.to_string())?; + if data_issues { + el.set_attribute("data-flaw", &ic.to_string())?; + } (None, None) } @@ -171,7 +177,9 @@ pub fn post_process_html( if resolved_href_no_hash == page.url() { el.set_attribute("aria-current", "page")?; } - if !Page::exists(resolved_href_no_hash) && !Page::ignore_link_check(href) { + let remove_href = if !Page::exists(resolved_href_no_hash) + && !Page::ignore_link_check(href) + { tracing::debug!("{resolved_href_no_hash} {href}"); let class = el.get_attribute("class").unwrap_or_default(); el.set_attribute( @@ -182,8 +190,12 @@ pub fn post_process_html( "page-not-created" ), )?; + el.remove_attribute("href"); el.set_attribute("title", l10n_json_data("Common", "summary", page.locale())?)?; - } + true + } else { + false + }; if original_href != resolved_href { if let Some(pos) = el.get_attribute("data-sourcepos") { if let Some((start, _)) = pos.split_once('-') { @@ -204,7 +216,9 @@ pub fn post_process_html( url = original_href, redirect = resolved_href.as_ref() ); - el.set_attribute("data-flaw", &ic.to_string())?; + if data_issues { + el.set_attribute("data-flaw", &ic.to_string())?; + } } } } else { @@ -215,17 +229,23 @@ pub fn post_process_html( url = original_href, redirect = resolved_href.as_ref() ); - el.set_attribute("data-flaw", &ic.to_string())?; + if data_issues { + el.set_attribute("data-flaw", &ic.to_string())?; + } } } - el.set_attribute( - "href", - if no_locale { - strip_locale_from_url(&resolved_href).1 - } else { - &resolved_href - }, - )?; + if remove_href { + el.remove_attribute("href"); + } else { + el.set_attribute( + "href", + if no_locale { + strip_locale_from_url(&resolved_href).1 + } else { + &resolved_href + }, + )?; + } } else if original_href.starts_with("http:") || original_href.starts_with("https:") { let class = el.get_attribute("class").unwrap_or_default(); if !class.split(' ').any(|s| s == "external") { diff --git a/crates/rari-types/src/settings.rs b/crates/rari-types/src/settings.rs index 8a9ffb9a..caf98849 100644 --- a/crates/rari-types/src/settings.rs +++ b/crates/rari-types/src/settings.rs @@ -23,6 +23,7 @@ pub struct Settings { pub interactive_examples_base_url: String, pub additional_locales_for_generics_and_spas: Vec, pub reader_ignores_gitignore: bool, + pub data_issues: bool, } impl Settings {