Skip to content

Commit e6771dc

Browse files
committed
chore(build): don't add inline (data) issues
1 parent 9aad2e2 commit e6771dc

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

crates/rari-cli/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct BuildArgs {
145145
templ_stats: bool,
146146
#[arg(long)]
147147
issues: Option<PathBuf>,
148+
#[arg(long)]
149+
data_issues: bool,
148150
}
149151

150152
enum Cache {
@@ -187,6 +189,7 @@ fn main() -> Result<(), Error> {
187189
let mut settings = Settings::new()?;
188190
settings.deny_warnings = args.deny_warnings;
189191
settings.cache_content = args.cache_content;
192+
settings.data_issues = args.data_issues;
190193
let _ = SETTINGS.set(settings);
191194

192195
let templ_stats = if args.templ_stats {
@@ -340,6 +343,7 @@ fn main() -> Result<(), Error> {
340343
let mut settings = Settings::new()?;
341344
settings.deny_warnings = args.deny_warnings;
342345
settings.cache_content = args.cache_content;
346+
settings.data_issues = true;
343347
let _ = SETTINGS.set(settings);
344348
serve::serve(memory_layer.clone())?
345349
}

crates/rari-doc/src/html/rewriter.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use lol_html::{element, rewrite_str, HtmlRewriter, RewriteStrSettings, Settings}
66
use rari_md::ext::DELIM_START;
77
use rari_md::node_card::NoteCard;
88
use rari_types::fm_types::PageType;
9+
use rari_types::globals::settings;
910
use rari_types::locale::Locale;
1011
use rari_utils::concat_strs;
1112
use tracing::warn;
@@ -51,6 +52,7 @@ pub fn post_process_html<T: PageLike>(
5152
if url.ends_with('/') { "" } else { "/" }
5253
))?;
5354
let base_url = options.base_url(Some(&base));
55+
let data_issues = settings().data_issues;
5456

5557
let mut element_content_handlers = vec![
5658
element!("*[id]", |el| {
@@ -110,7 +112,9 @@ pub fn post_process_html<T: PageLike>(
110112
"Error parsing {}: {e}",
111113
file.display()
112114
);
113-
el.set_attribute("data-flaw", &ic.to_string())?;
115+
if data_issues {
116+
el.set_attribute("data-flaw", &ic.to_string())?;
117+
}
114118
(None, None)
115119
}
116120
}
@@ -125,7 +129,9 @@ pub fn post_process_html<T: PageLike>(
125129
"Error opening {}: {e}",
126130
file.display()
127131
);
128-
el.set_attribute("data-flaw", &ic.to_string())?;
132+
if data_issues {
133+
el.set_attribute("data-flaw", &ic.to_string())?;
134+
}
129135

130136
(None, None)
131137
}
@@ -171,7 +177,9 @@ pub fn post_process_html<T: PageLike>(
171177
if resolved_href_no_hash == page.url() {
172178
el.set_attribute("aria-current", "page")?;
173179
}
174-
if !Page::exists(resolved_href_no_hash) && !Page::ignore_link_check(href) {
180+
let remove_href = if !Page::exists(resolved_href_no_hash)
181+
&& !Page::ignore_link_check(href)
182+
{
175183
tracing::debug!("{resolved_href_no_hash} {href}");
176184
let class = el.get_attribute("class").unwrap_or_default();
177185
el.set_attribute(
@@ -182,8 +190,12 @@ pub fn post_process_html<T: PageLike>(
182190
"page-not-created"
183191
),
184192
)?;
193+
el.remove_attribute("href");
185194
el.set_attribute("title", l10n_json_data("Common", "summary", page.locale())?)?;
186-
}
195+
true
196+
} else {
197+
false
198+
};
187199
if original_href != resolved_href {
188200
if let Some(pos) = el.get_attribute("data-sourcepos") {
189201
if let Some((start, _)) = pos.split_once('-') {
@@ -204,7 +216,9 @@ pub fn post_process_html<T: PageLike>(
204216
url = original_href,
205217
redirect = resolved_href.as_ref()
206218
);
207-
el.set_attribute("data-flaw", &ic.to_string())?;
219+
if data_issues {
220+
el.set_attribute("data-flaw", &ic.to_string())?;
221+
}
208222
}
209223
}
210224
} else {
@@ -215,17 +229,23 @@ pub fn post_process_html<T: PageLike>(
215229
url = original_href,
216230
redirect = resolved_href.as_ref()
217231
);
218-
el.set_attribute("data-flaw", &ic.to_string())?;
232+
if data_issues {
233+
el.set_attribute("data-flaw", &ic.to_string())?;
234+
}
219235
}
220236
}
221-
el.set_attribute(
222-
"href",
223-
if no_locale {
224-
strip_locale_from_url(&resolved_href).1
225-
} else {
226-
&resolved_href
227-
},
228-
)?;
237+
if remove_href {
238+
el.remove_attribute("href");
239+
} else {
240+
el.set_attribute(
241+
"href",
242+
if no_locale {
243+
strip_locale_from_url(&resolved_href).1
244+
} else {
245+
&resolved_href
246+
},
247+
)?;
248+
}
229249
} else if original_href.starts_with("http:") || original_href.starts_with("https:") {
230250
let class = el.get_attribute("class").unwrap_or_default();
231251
if !class.split(' ').any(|s| s == "external") {

crates/rari-types/src/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct Settings {
2323
pub interactive_examples_base_url: String,
2424
pub additional_locales_for_generics_and_spas: Vec<Locale>,
2525
pub reader_ignores_gitignore: bool,
26+
pub data_issues: bool,
2627
}
2728

2829
impl Settings {

0 commit comments

Comments
 (0)