Skip to content

Commit

Permalink
feat: change how logo paths were controlled inside rails application
Browse files Browse the repository at this point in the history
  • Loading branch information
mashirozx committed Jul 27, 2022
1 parent 406ee30 commit ae96da3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions app/helpers/branding_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/serializers/manifest_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }/
Expand Down

0 comments on commit ae96da3

Please sign in to comment.