Skip to content

Commit 5c96d7e

Browse files
committed
tidyup excessive whitespace, more clippy lints
1 parent b356dcb commit 5c96d7e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

tools/od_ref_bot/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn visit_dir(file: &mut File, dir: &str, from_dir: &String) -> Result<(), Box<dy
4747
.strip_prefix(from_dir)
4848
.unwrap()
4949
.to_string_lossy()
50-
.replace("\\", "/"),
50+
.replace('\\', "/"),
5151
path = inner_file.path().canonicalize().unwrap().display(),
5252
)?;
5353
}

tools/od_ref_bot/src/main.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn clean_query(query: String) -> String {
6262
/// Searches for exact path names, then page titles (from the frontmatter TOML)
6363
/// then searching through all path names for matches
6464
fn get_page<'a>(query: &'a String, data: &'a Data) -> Option<&'a str> {
65-
let mut path_find = query.replace(" ", "/");
65+
let mut path_find = query.replace(' ', "/");
6666

6767
if path_find.starts_with('/') {
6868
path_find = path_find[1..].to_string();
@@ -75,8 +75,8 @@ fn get_page<'a>(query: &'a String, data: &'a Data) -> Option<&'a str> {
7575
return Some(*string.0);
7676
}
7777

78-
if path_find.contains("/") {
79-
let components: Vec<&str> = path_find.split("/").collect();
78+
if path_find.contains('/') {
79+
let components: Vec<&str> = path_find.split('/').collect();
8080

8181
let mut var = components.clone();
8282
var.insert(components.len() - 1, "var");
@@ -146,7 +146,7 @@ fn format_embed(page: &str, data: &Data) -> Option<serenity::CreateEmbed> {
146146

147147
let mut title = parsed.title.clone()?;
148148

149-
let mut components: Vec<&str> = page.split("/").collect();
149+
let mut components: Vec<&str> = page.split('/').collect();
150150

151151
let proc = components.contains(&"proc");
152152
if proc || components.contains(&"var") {
@@ -169,7 +169,13 @@ fn format_embed(page: &str, data: &Data) -> Option<serenity::CreateEmbed> {
169169
.color(Colour::from_rgb(246, 114, 128))
170170
.description(format_body(body, data));
171171

172-
let extra = parsed.extra.as_ref().unwrap();
172+
let extra = parsed.extra.as_ref();
173+
174+
if extra.is_none() {
175+
return Some(embed);
176+
}
177+
178+
let extra = extra.unwrap();
173179

174180
if let Some(formats) = &extra.format {
175181
for format in formats.iter().enumerate() {
@@ -262,7 +268,7 @@ fn format_body(body: &str, data: &Data) -> String {
262268

263269
for capture in link_finder_regex.captures_iter(body) {
264270
let original = capture.get(0).unwrap().as_str();
265-
let type_string = capture.get(1).unwrap().as_str().replace("_", "/");
271+
let type_string = capture.get(1).unwrap().as_str().replace('_', "/");
266272

267273
let mut formatted = type_string.to_string();
268274

@@ -303,7 +309,8 @@ fn format_body(body: &str, data: &Data) -> String {
303309
let tag_cleaner_regex = Regex::new(r"\{\{.*?}}|\{%.*?%}").unwrap();
304310

305311
new_body = tag_cleaner_regex.replace_all(&new_body, "").to_string();
306-
new_body.replace("```dm", "```js")
312+
new_body = new_body.replace("```dm", "```js");
313+
new_body.replace("\n\n", "")
307314
}
308315

309316
/// Converts the internal Zola page structure into something we can link to.
@@ -313,7 +320,7 @@ fn get_url(path: &str, data: &PageFrontmatter) -> String {
313320
path = path.replace("_index", "");
314321

315322
if let Some(slug) = &data.slug {
316-
let mut components: Vec<&str> = path.split("/").collect();
323+
let mut components: Vec<&str> = path.split('/').collect();
317324
components.pop();
318325
components.push(slug.as_str());
319326

0 commit comments

Comments
 (0)