add legal page editor integration and media library polish
Some checks failed
deploy / deploy (push) Has been cancelled

Legal pages (privacy, delivery, terms) now auto-populate content from
shop settings on mount, show auto-generated vs customised badges, and
have a regenerate button. Theme editor gains alt text fields for logo,
header, and icon images. Image picker in page builder now has an upload
button and alt text warning badges. Clearing unused image references
shows an orphan info flash.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-28 17:55:02 +00:00
parent 3336b3aa26
commit 93ff66debc
9 changed files with 495 additions and 11 deletions

View File

@@ -442,4 +442,46 @@ defmodule Berrypod.LegalPages do
defp capitalise(<<first::utf8, rest::binary>>), do: String.upcase(<<first::utf8>>) <> rest
defp capitalise(""), do: ""
# =============================================================================
# Page editor integration
# =============================================================================
@legal_slugs ~w(privacy delivery terms)
@doc """
Returns true if the given slug is a legal page that supports regeneration.
"""
def legal_slug?(slug), do: slug in @legal_slugs
@doc """
Generates plain text content for a legal page, suitable for the
`content_body` block's textarea field.
"""
def regenerate_legal_content("privacy"), do: rich_text_to_plain(privacy_content())
def regenerate_legal_content("delivery"), do: rich_text_to_plain(delivery_content())
def regenerate_legal_content("terms"), do: rich_text_to_plain(terms_content())
@doc """
Converts rich text blocks (as returned by `*_content/0`) to a plain text
string with markdown-style headings. Double newlines separate sections.
"""
def rich_text_to_plain(blocks) when is_list(blocks) do
blocks
|> Enum.map(&block_to_text/1)
|> Enum.reject(&(&1 == ""))
|> Enum.join("\n\n")
end
defp block_to_text(%{type: :lead, text: text}), do: text
defp block_to_text(%{type: :heading, text: text}), do: "## #{text}"
defp block_to_text(%{type: :paragraph, text: text}), do: text
defp block_to_text(%{type: :list, items: items}) do
Enum.map_join(items, "\n", &"#{&1}")
end
defp block_to_text(%{type: :updated_at, date: date}), do: "Last updated: #{date}"
defp block_to_text(%{type: :closing, text: text}), do: text
defp block_to_text(_), do: ""
end