FEATURE: Allow themes to define screenshots (#29079)

This commit allows themes to define up to 2 screenshots
in about.json. These should be paths within the theme's
git repository, images with a 1MB max file size and max width 3840x2160.

These screenshots will be downloaded and stored against a theme
field, and we will use these in the redesigned theme grid UI.

These screenshots will be updated when the theme is updated
in the same way the additional theme files are.

For now this is gated behind a hidden `theme_download_screenshots`
site setting, to allow us to test this on a small number of sites without
making other sites make unnecessary uploads.

**Future considerations:**

* We may want to have a specialized naming system for screenshots. E.g. having light.png/dark.png/some_palette.png
* We may want to show more than one screenshot for the theme, maybe in a carousel or reacting to dark mode or color palette changes
* We may want to allow clicking on the theme screenshot to show a lightbox
* We may want to make an optimized thumbnail image for the theme grid

---------

Co-authored-by: Ted Johansson <ted@discourse.org>
This commit is contained in:
Martin Brennan
2024-10-28 10:10:20 +10:00
committed by GitHub
parent 77f63a45d3
commit 456fbb1dbf
8 changed files with 247 additions and 32 deletions

View File

@@ -13,7 +13,8 @@ class ThemeSerializer < BasicThemeSerializer
:description,
:enabled?,
:disabled_at,
:theme_fields
:theme_fields,
:screenshot_url
has_one :color_scheme, serializer: ColorSchemeSerializer, embed: :object
has_one :user, serializer: UserNameSerializer, embed: :object
@@ -47,6 +48,13 @@ class ThemeSerializer < BasicThemeSerializer
@include_theme_field_values || object.remote_theme_id.nil?
end
def screenshot_url
object
.theme_fields
.find { |field| field.type_id == ThemeField.types[:theme_screenshot_upload_var] }
&.upload_url
end
def child_themes
object.child_themes
end