Replace exact blank_to_nil helpers

This commit is contained in:
2026-06-21 14:31:29 +02:00
parent d3c21247e0
commit 67a1f8a5f0
5 changed files with 14 additions and 22 deletions

View File

@@ -327,7 +327,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor do
|> assign(:taxonomy_edit, %{
type: type,
name: name,
value: mapped_to |> to_string() |> blank_to_nil()
value: mapped_to |> to_string() |> BDS.MapUtils.blank_to_nil()
})
|> build_data()
@@ -1451,6 +1451,4 @@ defmodule BDS.Desktop.ShellLive.ImportEditor do
defp present?(value), do: value not in [nil, ""]
defp blank?(value), do: value in [nil, ""]
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value
end

View File

@@ -17,7 +17,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.TaxonomyEditing do
Map.put(socket.assigns.import_editor_taxonomy_edits, definition_id, %{
type: type,
name: name,
value: mapped_to |> to_string() |> blank_to_nil()
value: mapped_to |> to_string() |> BDS.MapUtils.blank_to_nil()
})
)
|> reload.(socket.assigns.workbench)
@@ -150,7 +150,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.TaxonomyEditing do
@spec update_taxonomy_mapping(term(), term(), term(), term()) :: term()
def update_taxonomy_mapping(report, type, name, mapped_to) do
bucket_key = if(type == "categories", do: :categories, else: :tags)
normalized_value = mapped_to |> to_string() |> String.trim() |> blank_to_nil()
normalized_value = mapped_to |> to_string() |> String.trim() |> BDS.MapUtils.blank_to_nil()
updated_report =
update_in(report, [:items, bucket_key], fn items ->
@@ -229,7 +229,7 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.TaxonomyEditing do
@spec normalize_taxonomy_mapping_value(term(), term(), term()) :: term()
def normalize_taxonomy_mapping_value(project_id, type, mapped_to) do
normalized_value = mapped_to |> to_string() |> String.trim() |> blank_to_nil()
normalized_value = mapped_to |> to_string() |> String.trim() |> BDS.MapUtils.blank_to_nil()
case normalized_value do
nil ->
@@ -285,6 +285,4 @@ defmodule BDS.Desktop.ShellLive.ImportEditor.TaxonomyEditing do
def maybe_put_option(opts, key, value), do: Keyword.put(opts, key, value)
defp present?(value), do: value not in [nil, ""]
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value
end

View File

@@ -175,11 +175,11 @@ defmodule BDS.ImportAnalysis do
resolution: if(status == "conflict", do: "ignore", else: nil),
existing_id: existing && existing.id,
existing_title: existing && existing.title,
author: blank_to_nil(wxr_post.creator),
excerpt: blank_to_nil(wxr_post.excerpt),
author: BDS.MapUtils.blank_to_nil(wxr_post.creator),
excerpt: BDS.MapUtils.blank_to_nil(wxr_post.excerpt),
categories: wxr_post.categories,
tags: wxr_post.tags,
wp_status: blank_to_nil(wxr_post.status),
wp_status: BDS.MapUtils.blank_to_nil(wxr_post.status),
content_markdown: content_markdown,
content_checksum: content_checksum,
content_preview: String.slice(content_markdown, 0, 200),
@@ -236,7 +236,7 @@ defmodule BDS.ImportAnalysis do
existing_id: existing && existing.id,
existing_title: existing && existing.title,
mime_type: wxr_media.mime_type,
description: blank_to_nil(wxr_media.description),
description: BDS.MapUtils.blank_to_nil(wxr_media.description),
parent_wp_id: wxr_media.parent_id,
source_file: source_file,
checksum: checksum,
@@ -546,7 +546,4 @@ defmodule BDS.ImportAnalysis do
end)
end
defp blank_to_nil(nil), do: nil
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value
end

View File

@@ -329,9 +329,9 @@ defmodule BDS.WxrParser do
slug: item.post_name,
content: item.content,
excerpt: item.excerpt,
pub_date: blank_to_nil(item.pub_date),
post_date: blank_to_nil(item.post_date),
post_modified: blank_to_nil(item.post_modified),
pub_date: BDS.MapUtils.blank_to_nil(item.pub_date),
post_date: BDS.MapUtils.blank_to_nil(item.post_date),
post_modified: BDS.MapUtils.blank_to_nil(item.post_modified),
creator: item.creator,
status: item.status,
post_type: item.post_type,
@@ -342,7 +342,7 @@ defmodule BDS.WxrParser do
defp parse_media_item(item) do
attachment_url = item.attachment_url
filename = attachment_url |> Path.basename() |> blank_to_nil() || ""
filename = attachment_url |> Path.basename() |> BDS.MapUtils.blank_to_nil() || ""
%{
wp_id: parse_integer(item.post_id),
@@ -350,7 +350,7 @@ defmodule BDS.WxrParser do
url: attachment_url,
filename: filename,
relative_path: relative_upload_path(attachment_url),
pub_date: blank_to_nil(item.pub_date),
pub_date: BDS.MapUtils.blank_to_nil(item.pub_date),
parent_id: parse_integer(item.post_parent),
mime_type: MIME.from_path(filename),
description: item.content
@@ -373,6 +373,4 @@ defmodule BDS.WxrParser do
end
end
defp blank_to_nil(""), do: nil
defp blank_to_nil(value), do: value
end