Skip to content

Commit

Permalink
chore(build): don't add inline (data) issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Oct 29, 2024
1 parent 9aad2e2 commit e6771dc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
4 changes: 4 additions & 0 deletions crates/rari-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ struct BuildArgs {
templ_stats: bool,
#[arg(long)]
issues: Option<PathBuf>,
#[arg(long)]
data_issues: bool,
}

enum Cache {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())?
}
Expand Down
48 changes: 34 additions & 14 deletions crates/rari-doc/src/html/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +52,7 @@ pub fn post_process_html<T: PageLike>(
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| {
Expand Down Expand Up @@ -110,7 +112,9 @@ pub fn post_process_html<T: PageLike>(
"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)
}
}
Expand All @@ -125,7 +129,9 @@ pub fn post_process_html<T: PageLike>(
"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)
}
Expand Down Expand Up @@ -171,7 +177,9 @@ pub fn post_process_html<T: PageLike>(
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(
Expand All @@ -182,8 +190,12 @@ pub fn post_process_html<T: PageLike>(
"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('-') {
Expand All @@ -204,7 +216,9 @@ pub fn post_process_html<T: PageLike>(
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 {
Expand All @@ -215,17 +229,23 @@ pub fn post_process_html<T: PageLike>(
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") {
Expand Down
1 change: 1 addition & 0 deletions crates/rari-types/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Settings {
pub interactive_examples_base_url: String,
pub additional_locales_for_generics_and_spas: Vec<Locale>,
pub reader_ignores_gitignore: bool,
pub data_issues: bool,
}

impl Settings {
Expand Down

0 comments on commit e6771dc

Please sign in to comment.