fix(style): replace Map.get with dot access and pattern matching where keys are guaranteed (CSM-032)
This commit is contained in:
@@ -118,7 +118,7 @@ defmodule BDS.Generation.Data do
|
||||
main = String.downcase(to_string(main_language || ""))
|
||||
|
||||
Enum.map(posts, fn post ->
|
||||
post_language = String.downcase(to_string(Map.get(post, :language) || ""))
|
||||
post_language = String.downcase(to_string(post.language || ""))
|
||||
effective_language = if post_language == "", do: main, else: post_language
|
||||
|
||||
cond do
|
||||
@@ -373,18 +373,18 @@ defmodule BDS.Generation.Data do
|
||||
excerpt: translation.excerpt,
|
||||
content: nil,
|
||||
status: :published,
|
||||
author: Map.get(post, :author),
|
||||
author: post.author,
|
||||
created_at: post.created_at,
|
||||
updated_at: translation.updated_at,
|
||||
published_at: translation.published_at || post.published_at,
|
||||
file_path: translation.file_path,
|
||||
tags: Map.get(post, :tags, []),
|
||||
categories: Map.get(post, :categories, []),
|
||||
template_slug: Map.get(post, :template_slug),
|
||||
tags: post.tags,
|
||||
categories: post.categories,
|
||||
template_slug: post.template_slug,
|
||||
language: translation.language,
|
||||
do_not_translate: Map.get(post, :do_not_translate, false),
|
||||
do_not_translate: post.do_not_translate,
|
||||
translation_source_slug: post.slug,
|
||||
translation_canonical_language: Map.get(post, :language),
|
||||
translation_canonical_language: post.language,
|
||||
translation_file_path: translation.file_path
|
||||
}
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ defmodule BDS.Generation.Outputs do
|
||||
|
||||
Enum.reject(route_posts, fn post ->
|
||||
is_binary(Map.get(post, :translation_source_slug)) and
|
||||
MapSet.member?(subtree_languages, to_string(Map.get(post, :language)))
|
||||
MapSet.member?(subtree_languages, to_string(post.language))
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -432,11 +432,11 @@ defmodule BDS.Generation.Outputs do
|
||||
title: post.title,
|
||||
content: body,
|
||||
slug: post.slug,
|
||||
language: Map.get(post, :language),
|
||||
language: post.language,
|
||||
excerpt: post.excerpt,
|
||||
_post_record: post
|
||||
},
|
||||
fn -> render_post_page(post.title, body, post.slug, Map.get(post, :language)) end
|
||||
fn -> render_post_page(post.title, body, post.slug, post.language) end
|
||||
)}
|
||||
end)
|
||||
end)
|
||||
@@ -560,11 +560,11 @@ defmodule BDS.Generation.Outputs do
|
||||
title: post.title,
|
||||
content: body,
|
||||
slug: post.slug,
|
||||
language: Map.get(post, :language),
|
||||
language: post.language,
|
||||
excerpt: post.excerpt,
|
||||
_post_record: post
|
||||
},
|
||||
fn -> render_post_page(post.title, body, post.slug, Map.get(post, :language)) end
|
||||
fn -> render_post_page(post.title, body, post.slug, post.language) end
|
||||
)}
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -75,7 +75,7 @@ defmodule BDS.Generation.Sitemap do
|
||||
page_path = Paths.relative_path_to_url_path(Paths.page_output_path(post.slug, nil))
|
||||
|
||||
languages =
|
||||
if Paths.truthy_flag?(Map.get(post, :do_not_translate)),
|
||||
if Paths.truthy_flag?(post.do_not_translate),
|
||||
do: [plan.language],
|
||||
else: all_languages
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ defmodule BDS.Generation.Validation do
|
||||
post_file_path:
|
||||
source_full_path(
|
||||
project_data_dir,
|
||||
Map.get(post, :translation_file_path) || Map.get(post, :file_path)
|
||||
Map.get(post, :translation_file_path) || post.file_path
|
||||
),
|
||||
generated_updated_at_ms: Map.get(generated_file_updated_at, relative_path, 0)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ defmodule BDS.Generation.Validation do
|
||||
|
||||
%{
|
||||
post_url_path: relative_path_to_url_path(relative_path),
|
||||
post_file_path: source_full_path(project_data_dir, Map.get(post, :file_path)),
|
||||
post_file_path: source_full_path(project_data_dir, post.file_path),
|
||||
generated_updated_at_ms: Map.get(generated_file_updated_at, relative_path, 0)
|
||||
}
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user