fix: reworking some code smell issues
This commit is contained in:
@@ -238,26 +238,27 @@ defmodule BDS.Rendering.Filters do
|
||||
path_part |> String.replace(~r/\.html?$/i, "")
|
||||
|
||||
match = Regex.run(~r|^/?post/([a-z0-9-]+(?:\.html?)?)$|i, path_part) ->
|
||||
slug = match |> Enum.at(1) |> String.replace(~r/\.html?$/i, "")
|
||||
Map.get(canonical_post_paths, slug)
|
||||
slug_from_match(match, canonical_post_paths)
|
||||
|
||||
match = Regex.run(~r|^/?post/\d{4}/\d{1,2}/([a-z0-9-]+(?:\.html?)?)$|i, path_part) ->
|
||||
slug = match |> Enum.at(1) |> String.replace(~r/\.html?$/i, "")
|
||||
Map.get(canonical_post_paths, slug)
|
||||
slug_from_match(match, canonical_post_paths)
|
||||
|
||||
match = Regex.run(~r|^/?posts/([a-z0-9-]+(?:\.html?)?)$|i, path_part) ->
|
||||
slug = match |> Enum.at(1) |> String.replace(~r/\.html?$/i, "")
|
||||
Map.get(canonical_post_paths, slug)
|
||||
slug_from_match(match, canonical_post_paths)
|
||||
|
||||
match = Regex.run(~r|^/?posts/\d{4}/\d{1,2}/([a-z0-9-]+(?:\.html?)?)$|i, path_part) ->
|
||||
slug = match |> Enum.at(1) |> String.replace(~r/\.html?$/i, "")
|
||||
Map.get(canonical_post_paths, slug)
|
||||
slug_from_match(match, canonical_post_paths)
|
||||
|
||||
true ->
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
defp slug_from_match([_full, captured], canonical_post_paths) do
|
||||
slug = String.replace(captured, ~r/\.html?$/i, "")
|
||||
Map.get(canonical_post_paths, slug)
|
||||
end
|
||||
|
||||
defp normalize_media_src(raw_src, canonical_media_paths) do
|
||||
cond do
|
||||
raw_src == "" ->
|
||||
|
||||
@@ -120,7 +120,7 @@ defmodule BDS.Rendering.LinksAndLanguages do
|
||||
|
||||
defp post_date_path_parts(created_at) do
|
||||
datetime = Persistence.from_unix_ms!(created_at)
|
||||
year_month_path_parts(datetime) ++ [pad2(datetime.day)]
|
||||
year_month_path_parts(datetime) ++ [BDS.Strings.pad2(datetime.day)]
|
||||
end
|
||||
|
||||
defp year_month_path_parts(created_at) when is_integer(created_at) do
|
||||
@@ -130,13 +130,11 @@ defmodule BDS.Rendering.LinksAndLanguages do
|
||||
end
|
||||
|
||||
defp year_month_path_parts(%DateTime{} = datetime) do
|
||||
[Integer.to_string(datetime.year), pad2(datetime.month)]
|
||||
[Integer.to_string(datetime.year), BDS.Strings.pad2(datetime.month)]
|
||||
end
|
||||
|
||||
defp normalize_language_prefix(prefix) when is_binary(prefix) and prefix != "",
|
||||
do: String.trim_trailing(prefix, "/")
|
||||
|
||||
defp normalize_language_prefix(_prefix), do: ""
|
||||
|
||||
defp pad2(value), do: value |> Integer.to_string() |> String.pad_leading(2, "0")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user