add favicon and site icon generation from uploaded images
All checks were successful
deploy / deploy (push) Successful in 1m26s
All checks were successful
deploy / deploy (push) Successful in 1m26s
Upload a source image (PNG, JPEG, or SVG) and get a complete favicon setup: PNG variants at 32, 180, 192, 512px served from DB via FaviconController with ETag caching, SVG favicon for vector sources, dynamic site.webmanifest, and theme-color meta tag. Theme editor gains a site icon section with "use logo as icon" toggle, dedicated icon upload, short name, and background colour picker. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
26
lib/berrypod/media/favicon_variant.ex
Normal file
26
lib/berrypod/media/favicon_variant.ex
Normal file
@@ -0,0 +1,26 @@
|
||||
defmodule Berrypod.Media.FaviconVariant do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
|
||||
schema "favicon_variants" do
|
||||
field :source_image_id, :binary_id
|
||||
field :png_32, :binary
|
||||
field :png_180, :binary
|
||||
field :png_192, :binary
|
||||
field :png_512, :binary
|
||||
field :svg, :string
|
||||
field :generated_at, :utc_datetime
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(variant, attrs) do
|
||||
variant
|
||||
|> cast(attrs, [:source_image_id, :png_32, :png_180, :png_192, :png_512, :svg, :generated_at])
|
||||
|> validate_required([:source_image_id, :generated_at])
|
||||
end
|
||||
end
|
||||
@@ -38,7 +38,7 @@ defmodule Berrypod.Media.Image do
|
||||
:variants_status
|
||||
])
|
||||
|> validate_required([:image_type, :filename, :content_type, :file_size, :data])
|
||||
|> validate_inclusion(:image_type, ~w(logo header product))
|
||||
|> validate_inclusion(:image_type, ~w(logo header product icon))
|
||||
|> validate_number(:file_size, less_than: @max_file_size)
|
||||
|> detect_svg()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user