From ae96da3502141d676dfd787e3c66c154fa06fd8e Mon Sep 17 00:00:00 2001 From: mashirozx Date: Wed, 27 Jul 2022 17:03:16 +0800 Subject: [PATCH] feat: change how logo paths were controlled inside rails application --- .env.production.sample | 7 +++++++ app/helpers/branding_helper.rb | 10 +++++++--- app/serializers/manifest_serializer.rb | 2 +- app/views/layouts/application.html.haml | 6 +++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.env.production.sample b/.env.production.sample index a43432c65babb4..bfd70ac65debb3 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -162,3 +162,10 @@ AZURE_OAUTH2_KEY=your_key AZURE_OAUTH2_SECRET=your_secret # optional tenant id if using a multi-tenant azure account: http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx AZURE_OAUTH2_TENANT_ID=your_tenant_id + +# Logo pack +# Use custom logo pack, see details in `./design/` +# See detailed guidance (Chinese): https://littlefo.rest/@mashiro/108718664789141341 +# Note this will only change the path of assets generated on Rails side, for the assets controlled inside webpack, use Nginx +# redirection instead. +LOGO_PACK=_forest diff --git a/app/helpers/branding_helper.rb b/app/helpers/branding_helper.rb index ad7702aea71a8b..857e556290bad1 100644 --- a/app/helpers/branding_helper.rb +++ b/app/helpers/branding_helper.rb @@ -19,19 +19,23 @@ def _logo_as_symbol_icon end def render_logo - image_pack_tag('logo.svg', alt: 'Mastodon', class: 'logo logo--icon') + image_pack_tag("logo#{suffix}.svg", alt: 'Mastodon', class: 'logo logo--icon') end def render_symbol(version = :icon) path = begin case version when :icon - 'logo-symbol-icon.svg' + "logo-symbol-icon#{suffix}.svg" when :wordmark - 'logo-symbol-wordmark.svg' + "logo-symbol-wordmark#{suffix}.svg" end end render(file: Rails.root.join('app', 'javascript', 'images', path)).html_safe # rubocop:disable Rails/OutputSafety end + + def suffix + ENV['LOGO_PACK'] || '' + end end diff --git a/app/serializers/manifest_serializer.rb b/app/serializers/manifest_serializer.rb index 9827323a81dd84..5f6cdf030dd910 100644 --- a/app/serializers/manifest_serializer.rb +++ b/app/serializers/manifest_serializer.rb @@ -32,7 +32,7 @@ def short_name def icons ICON_SIZES.map do |size| { - src: full_pack_url("media/icons/android-chrome-#{size}x#{size}.png"), + src: full_pack_url("media/icons/android-chrome-#{size}x#{size}#{ENV['LOGO_PACK'] || ''}.png"), sizes: "#{size}x#{size}", type: 'image/png', } diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 85b71d7e4f4ba6..3893c64dbdce80 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -19,12 +19,12 @@ %link{ rel: 'icon', href: '/favicon.ico', type: 'image/x-icon' }/ - %w(16 32 48).each do |size| - %link{ rel: 'icon', sizes: "#{size}x#{size}", href: asset_pack_path("media/icons/favicon-#{size}x#{size}.png"), type: 'image/png' }/ + %link{ rel: 'icon', sizes: "#{size}x#{size}", href: asset_pack_path("media/icons/favicon-#{size}x#{size}#{ENV['LOGO_PACK'] || ''}.png"), type: 'image/png' }/ - %w(57 60 72 76 114 120 144 152 167 180 1024).each do |size| - %link{ rel: 'apple-touch-icon', sizes: "#{size}x#{size}", href: asset_pack_path("media/icons/apple-touch-icon-#{size}x#{size}.png") }/ + %link{ rel: 'apple-touch-icon', sizes: "#{size}x#{size}", href: asset_pack_path("media/icons/apple-touch-icon-#{size}x#{size}#{ENV['LOGO_PACK'] || ''}.png") }/ - %link{ rel: 'mask-icon', href: asset_pack_path('media/images/logo-symbol-icon.svg'), color: '#6364FF' }/ + %link{ rel: 'mask-icon', href: asset_pack_path("media/images/logo-symbol-icon#{ENV['LOGO_PACK'] || ''}.svg"), color: '#6364FF' }/ %link{ rel: 'manifest', href: manifest_path(format: :json) }/ %meta{ name: 'theme-color', content: '#282c37' }/ %meta{ name: 'apple-mobile-web-app-capable', content: 'yes' }/