Fix #4111: Cache custom CSS.
This commit is contained in:
@@ -75,6 +75,11 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def custom_style
|
||||
@css = CustomCss.parse(CurrentUser.user.custom_style)
|
||||
expires_in 10.years
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_privilege(user)
|
||||
|
||||
11
app/logical/custom_css.rb
Normal file
11
app/logical/custom_css.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module CustomCss
|
||||
def self.parse(css)
|
||||
css.to_s.split(/\r\n|\r|\n/).map do |line|
|
||||
if line =~ /\A@import/
|
||||
line
|
||||
else
|
||||
line.gsub(/([^[:space:]])[[:space:]]*(?:!important)?[[:space:]]*(;|})/, "\\1 !important\\2")
|
||||
end
|
||||
end.join("\n")
|
||||
end
|
||||
end
|
||||
@@ -172,14 +172,4 @@ class UserPresenter
|
||||
def previous_names(template)
|
||||
user.user_name_change_requests.map { |req| template.link_to req.original_name, req }.join(", ").html_safe
|
||||
end
|
||||
|
||||
def custom_css
|
||||
user.custom_style.to_s.split(/\r\n|\r|\n/).map do |line|
|
||||
if line =~ /\A@import/
|
||||
line
|
||||
else
|
||||
line.gsub(/([^[:space:]])[[:space:]]*(?:!important)?[[:space:]]*(;|})/, "\\1 !important\\2")
|
||||
end
|
||||
end.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<%= javascript_pack_tag "application" %>
|
||||
<%= stylesheet_pack_tag "application" %>
|
||||
<% if CurrentUser.user.custom_style.present? %>
|
||||
<%= stylesheet_link_tag custom_style_users_path, :media => "screen" %>
|
||||
<%= stylesheet_link_tag custom_style_users_path(md5: Digest::MD5.hexdigest(CurrentUser.user.custom_style)), media: "screen" %>
|
||||
<% end %>
|
||||
<% if Danbooru.config.twitter_site %>
|
||||
<script type="application/ld+json">
|
||||
|
||||
@@ -1 +1 @@
|
||||
<%= raw CurrentUser.user.presenter.custom_css %>
|
||||
<%= raw @css %>
|
||||
|
||||
Reference in New Issue
Block a user