]> cat aescling's git repositories - mastodon.git/commitdiff
Add admin custom CSS setting (#8399)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 24 Aug 2018 02:33:27 +0000 (04:33 +0200)
committerGitHub <noreply@github.com>
Fri, 24 Aug 2018 02:33:27 +0000 (04:33 +0200)
Fix #3894

app/controllers/admin/settings_controller.rb
app/controllers/custom_css_controller.rb [new file with mode: 0644]
app/javascript/styles/mastodon/forms.scss
app/models/form/admin_settings.rb
app/presenters/instance_presenter.rb
app/views/admin/settings/edit.html.haml
app/views/layouts/application.html.haml
config/routes.rb

index 23e0444d0f9f78538d3c44fcf346717eecc0eb80..7d38f76aea482237dd97b92857eec76062fb73fd 100644 (file)
@@ -24,6 +24,7 @@ module Admin
       peers_api_enabled
       show_known_fediverse_at_about_page
       preview_sensitive_media
+      custom_css
     ).freeze
 
     BOOLEAN_SETTINGS = %w(
diff --git a/app/controllers/custom_css_controller.rb b/app/controllers/custom_css_controller.rb
new file mode 100644 (file)
index 0000000..31e5016
--- /dev/null
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class CustomCssController < ApplicationController
+  before_action :set_cache_headers
+
+  def show
+    skip_session!
+    render plain: Setting.custom_css || '', content_type: 'text/css'
+  end
+end
index 020be5ad2e255cbb3a397c2eaf5144dd7d17393e..144b4a519ce45dc5d77b797e7c16c052b4703ec6 100644 (file)
@@ -621,3 +621,14 @@ code {
 .scope-danger {
   color: $warning-red;
 }
+
+.form_admin_settings_site_short_description,
+.form_admin_settings_site_description,
+.form_admin_settings_site_extended_description,
+.form_admin_settings_site_terms,
+.form_admin_settings_custom_css,
+.form_admin_settings_closed_registrations_message {
+  textarea {
+    font-family: 'mastodon-font-monospace', monospace;
+  }
+}
index db46cda7b558f2b171f1f8aa6943cf05d33249e5..9fef7da97fc87fa165039f377152915a360b353b 100644 (file)
@@ -42,6 +42,8 @@ class Form::AdminSettings
     :show_known_fediverse_at_about_page=,
     :preview_sensitive_media,
     :preview_sensitive_media=,
+    :custom_css,
+    :custom_css=,
     to: Setting
   )
 end
index 31365b64686a84dd75dfde34bdaeb3142d9dbba7..a4e4af8894ae985e78c10e4552039cadc5882f59 100644 (file)
@@ -14,7 +14,7 @@ class InstancePresenter
   )
 
   def contact_account
-    Account.find_local(Setting.site_contact_username)
+    Account.find_local(Setting.site_contact_username.gsub(/\A@/, ''))
   end
 
   def user_count
index b5aa176a2ff6768ef4299956ba127af6f69c8af5..f40edc35a51dbfeea032ed82b95edfeaa40a7f90 100644 (file)
@@ -49,7 +49,7 @@
   .fields-group
     = f.input :site_extended_description, wrapper: :with_block_label, as: :text, label: t('admin.settings.site_description_extended.title'), hint: t('admin.settings.site_description_extended.desc_html'), input_html: { rows: 8 }
     = f.input :site_terms, wrapper: :with_block_label, as: :text, label: t('admin.settings.site_terms.title'), hint: t('admin.settings.site_terms.desc_html'), input_html: { rows: 8 }
-
+    = f.input :custom_css, wrapper: :with_block_label, as: :text, input_html: { rows: 8 }, label: t('admin.settings.custom_css.title'), hint: t('admin.settings.custom_css.desc_html')
   %hr/
 
   .fields-group
index df898d5a20bb33759e8bc66896a547fcb6d93aec..68a903197b7dd19ebb6e61dde3d45ae94a5617ce 100755 (executable)
@@ -19,6 +19,9 @@
     = javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous'
     = csrf_meta_tags
 
+    - if Setting.custom_css.present?
+      = stylesheet_link_tag custom_css_path, media: 'all'
+
     = yield :header_tags
 
   - body_classes ||= @body_classes || ''
index 80a8b7b4c90218f56b909a7f46d2d54fdb8c3a6b..0e54157dc5efe038855a9ab6087ba9f80cdaddc8 100644 (file)
@@ -23,6 +23,7 @@ Rails.application.routes.draw do
   get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
   get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
   get 'intent', to: 'intents#show'
+  get 'custom.css', to: 'custom_css#show', as: :custom_css
 
   devise_scope :user do
     get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite