Ensure custom favicon is converted to PNG and ICO (#30208)

pull/30214/head
Claire 2024-05-07 20:15:17 +02:00 committed by GitHub
parent c9ccba7045
commit d8c4284723
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 4 deletions

View File

@ -26,8 +26,23 @@ class SiteUpload < ApplicationRecord
APP_ICON_SIZES = (APPLE_ICON_SIZES + ANDROID_ICON_SIZES).uniq.freeze APP_ICON_SIZES = (APPLE_ICON_SIZES + ANDROID_ICON_SIZES).uniq.freeze
STYLES = { STYLES = {
app_icon: APP_ICON_SIZES.each_with_object({}) { |size, hash| hash[size.to_s.to_sym] = "#{size}x#{size}#" }.freeze, app_icon:
favicon: FAVICON_SIZES.each_with_object({}) { |size, hash| hash[size.to_s.to_sym] = "#{size}x#{size}#" }.freeze, APP_ICON_SIZES.to_h do |size|
[:"#{size}", { format: 'png', geometry: "#{size}x#{size}#", file_geometry_parser: FastGeometryParser }]
end.freeze,
favicon: {
ico: {
format: 'ico',
geometry: '48x48#',
file_geometry_parser: FastGeometryParser,
}.freeze,
}.merge(
FAVICON_SIZES.to_h do |size|
[:"#{size}", { format: 'png', geometry: "#{size}x#{size}#", file_geometry_parser: FastGeometryParser }]
end
).freeze,
thumbnail: { thumbnail: {
'@1x': { '@1x': {
format: 'png', format: 'png',

View File

@ -11,7 +11,7 @@
- if storage_host? - if storage_host?
%link{ rel: 'dns-prefetch', href: storage_host }/ %link{ rel: 'dns-prefetch', href: storage_host }/
%link{ rel: 'icon', href: site_icon_path('favicon') || '/favicon.ico', type: 'image/x-icon' }/ %link{ rel: 'icon', href: site_icon_path('favicon', 'ico') || '/favicon.ico', type: 'image/x-icon' }/
- SiteUpload::FAVICON_SIZES.each do |size| - SiteUpload::FAVICON_SIZES.each do |size|
%link{ rel: 'icon', sizes: "#{size}x#{size}", href: site_icon_path('favicon', size.to_i) || frontend_asset_path("icons/favicon-#{size}x#{size}.png"), type: 'image/png' }/ %link{ rel: 'icon', sizes: "#{size}x#{size}", href: site_icon_path('favicon', size.to_i) || frontend_asset_path("icons/favicon-#{size}x#{size}.png"), type: 'image/png' }/

View File

@ -23,5 +23,5 @@
<!-- Disallow any coder by default, and only enable ones required by Mastodon --> <!-- Disallow any coder by default, and only enable ones required by Mastodon -->
<policy domain="coder" rights="none" pattern="*" /> <policy domain="coder" rights="none" pattern="*" />
<policy domain="coder" rights="read | write" pattern="{JPEG,PNG,GIF,WEBP,HEIC,AVIF}" /> <policy domain="coder" rights="read | write" pattern="{JPEG,PNG,GIF,WEBP,HEIC,AVIF}" />
<policy domain="coder" rights="write" pattern="{HISTOGRAM,RGB,INFO}" /> <policy domain="coder" rights="write" pattern="{HISTOGRAM,RGB,INFO,ICO}" />
</policymap> </policymap>