Skip to content

Commit

Permalink
Code tidy-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Jun 18, 2024
1 parent b33a92c commit 236d1a1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 23 deletions.
4 changes: 1 addition & 3 deletions rosey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ impl RoseyTranslation {
keys.insert(key, value);
}
RoseyTranslation::V2(keys) => {
let translation = keys
.entry(key)
.or_insert_with(|| RoseyTranslationEntry::new(value));
keys.insert(key, RoseyTranslationEntry::new(value));
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions rosey/src/runners/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl RoseyBuilder {
let walker = globwalk::GlobWalkerBuilder::from_patterns(&config.source, &["**/*"])
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok)
.filter(|file| {
file.file_type().is_file() && !re.is_match(&file.path().to_string_lossy())
Expand Down Expand Up @@ -133,7 +132,6 @@ impl RoseyBuilder {
globwalk::GlobWalkerBuilder::from_patterns(source_folder, &["**/*.{html,json}"])
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok)
.partition(|file| self.find_locale_overwrite(file.path()).is_none());

Expand Down Expand Up @@ -165,7 +163,6 @@ impl RoseyBuilder {
let walker = globwalk::GlobWalkerBuilder::from_patterns(&config.locales, &["**/*.json"])
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);

walker.for_each(|file| {
Expand Down
21 changes: 8 additions & 13 deletions rosey/src/runners/builder/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ impl RoseyBuilder {
page.rewrite_anchors(default_url_translations);

let translated_default_url = default_url_translations
.map(|t| t.get(&relative_path.to_slash_lossy()))
.flatten()
.and_then(|t| t.get(&relative_path.to_slash_lossy()))
.map(Into::into)
.unwrap_or_else(|| relative_path.to_owned());

Expand All @@ -98,8 +97,7 @@ impl RoseyBuilder {
let url_translations = self.url_translations.get(key);

let translated_url = url_translations
.map(|t| t.get(&relative_path.to_slash_lossy()))
.flatten()
.and_then(|t| t.get(&relative_path.to_slash_lossy()))
.map(Into::into)
.unwrap_or_else(|| relative_path.to_owned());

Expand Down Expand Up @@ -145,8 +143,7 @@ impl RoseyBuilder {
{
let translated_path = url_translations
.get(key)
.map(|t| t.get(&relative_path.to_slash_lossy()))
.flatten()
.and_then(|t| t.get(&relative_path.to_slash_lossy()))
.map(|p| filepath_to_output_url(p))
.unwrap_or_else(|| path.clone());

Expand Down Expand Up @@ -176,8 +173,7 @@ impl RoseyBuilder {

let translated_default_url = if let Some(translated_url) = url_translations
.get(locale)
.map(|t| t.get(&relative_path.to_slash_lossy()))
.flatten()
.and_then(|t| t.get(&relative_path.to_slash_lossy()))
{
filepath_to_output_url(translated_url)
} else {
Expand Down Expand Up @@ -331,9 +327,9 @@ impl<'a> RoseyPage<'a> {
}

if let Some(urlmap) = url_translations {
let rel_url = parsed.path().trim_start_matches("/");
let rel_url = parsed.path().trim_start_matches('/');

let candidate_url = if rel_url.ends_with("/") {
let candidate_url = if rel_url.ends_with('/') {
format!("{rel_url}index.html")
} else if rel_url.ends_with(".html") || rel_url.ends_with(".htm") {
rel_url.to_string()
Expand All @@ -342,7 +338,7 @@ impl<'a> RoseyPage<'a> {
};

if let Some(modified_url) = urlmap.get(&candidate_url) {
parsed.set_path(&filepath_to_output_url(&modified_url));
parsed.set_path(&filepath_to_output_url(modified_url));
}
}

Expand Down Expand Up @@ -591,8 +587,7 @@ impl<'a> RoseyPage<'a> {
{
let translated_path = url_translations
.get(key)
.map(|t| t.get(&original_relative_path.to_slash_lossy()))
.flatten()
.and_then(|t| t.get(&original_relative_path.to_slash_lossy()))
.map(|p| filepath_to_output_url(p))
.unwrap_or_else(|| {
filepath_to_output_url(&original_relative_path.to_slash_lossy())
Expand Down
2 changes: 1 addition & 1 deletion rosey/src/runners/builder/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl RoseyBuilder {
let mut array_namespace = false;
let mut key = None;

match schema_array.get(0) {
match schema_array.first() {
Some(Value::String(schema_value)) => {
schema_value.trim().split('|').for_each(|part| {
if part == "rosey-array-ns" {
Expand Down
1 change: 0 additions & 1 deletion rosey/src/runners/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ impl RoseyChecker {
let walker = globwalk::GlobWalkerBuilder::from_patterns(&config.locales, &["**/*.json"])
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);

walker.for_each(|entry| self.process_file(entry));
Expand Down
1 change: 0 additions & 1 deletion rosey/src/runners/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl RoseyGenerator {
globwalk::GlobWalkerBuilder::from_patterns(&config.source, &["**/*.{htm,html,json}"])
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok);

walker.for_each(|file| self.process_file(file));
Expand Down
2 changes: 1 addition & 1 deletion rosey/src/runners/generator/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl RoseyGenerator {
let mut array_namespace = false;
let mut key = None;

match schema_array.get(0) {
match schema_array.first() {
Some(Value::String(schema_value)) => {
schema_value.trim().split('|').for_each(|part| {
if part == "rosey-array-ns" {
Expand Down

0 comments on commit 236d1a1

Please sign in to comment.