mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 10:34:39 +08:00
DEV: Revert stylesheet refactors (#13584)
* Revert "FIX: Clear appropriate cache when updating font settings (#13582)" This reverts commit de6cc7a92412538b2460e1b6f4855da343054899. * Revert "DEV: Improve output of `Stylesheet::Mananger.precompile_theme_css`." This reverts commit 95038856c9ddeee7d0d8083a75006a5e3492dd54. * Revert "FIX: Child themes being precompiled multiple times." This reverts commit 6986b36985fa242cb3d346b05f84d3878573c354. * Revert "Update spec/components/stylesheet/manager_spec.rb" This reverts commit ddaa7cc7eac2850f9a8614077c1170942ebc0311. * Revert "Refactor scss live refreshing" This reverts commit a838293aaf1e3b21c34c1964603e1b85c5673935. * Revert "Precompile core stylesheets independently of themes" This reverts commit 99d259d39bdaade6d20951c84def890dc91246a5. * Revert "DEV: Add simple digest for core stylesheets" This reverts commit d82c58e6cc5dd43b8bfb062838a24cac85ac9ca2.
This commit is contained in:
@ -29,6 +29,9 @@ module Stylesheet
|
||||
file += File.read path
|
||||
|
||||
case asset.to_s
|
||||
when "desktop", "mobile"
|
||||
file += importer.category_backgrounds
|
||||
file += importer.font
|
||||
when "embed", "publish"
|
||||
file += importer.font
|
||||
when "wizard"
|
||||
@ -36,8 +39,6 @@ module Stylesheet
|
||||
when Stylesheet::Manager::COLOR_SCHEME_STYLESHEET
|
||||
file += importer.import_color_definitions
|
||||
file += importer.import_wcag_overrides
|
||||
file += importer.category_backgrounds
|
||||
file += importer.font
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,58 +42,52 @@ class Stylesheet::Manager
|
||||
end
|
||||
|
||||
def self.precompile_css
|
||||
targets = [:desktop, :mobile, :desktop_rtl, :mobile_rtl, :admin, :wizard]
|
||||
targets += Discourse.find_plugin_css_assets(include_disabled: true, mobile_view: true, desktop_view: true)
|
||||
|
||||
targets.each do |target|
|
||||
$stderr.puts "precompile target: #{target}"
|
||||
|
||||
Stylesheet::Manager::Builder.new(target: target, manager: nil).compile(force: true)
|
||||
end
|
||||
end
|
||||
|
||||
def self.precompile_theme_css
|
||||
themes = Theme.where('user_selectable OR id = ?', SiteSetting.default_theme_id).pluck(:id, :color_scheme_id)
|
||||
themes = Theme.where('user_selectable OR id = ?', SiteSetting.default_theme_id).pluck(:id, :name, :color_scheme_id)
|
||||
themes << nil
|
||||
|
||||
color_schemes = ColorScheme.where(user_selectable: true).to_a
|
||||
color_schemes << ColorScheme.find_by(id: SiteSetting.default_dark_mode_color_scheme_id)
|
||||
color_schemes << ColorScheme.base
|
||||
color_schemes = color_schemes.compact.uniq
|
||||
|
||||
targets = [:desktop_theme, :mobile_theme]
|
||||
compiled = Set.new
|
||||
targets = [:desktop, :mobile, :desktop_rtl, :mobile_rtl, :desktop_theme, :mobile_theme, :admin, :wizard]
|
||||
targets += Discourse.find_plugin_css_assets(include_disabled: true, mobile_view: true, desktop_view: true)
|
||||
|
||||
themes.each do |theme_id, color_scheme_id|
|
||||
themes.each do |id, name, color_scheme_id|
|
||||
theme_id = id || SiteSetting.default_theme_id
|
||||
manager = self.new(theme_id: theme_id)
|
||||
|
||||
targets.each do |target|
|
||||
next if theme_id == -1
|
||||
if target =~ THEME_REGEX
|
||||
next if theme_id == -1
|
||||
|
||||
scss_checker = ScssChecker.new(target, manager.theme_ids)
|
||||
scss_checker = ScssChecker.new(target, manager.theme_ids)
|
||||
|
||||
manager.load_themes(manager.theme_ids).each do |theme|
|
||||
next if compiled.include?("#{target}_#{theme.id}")
|
||||
manager.load_themes(manager.theme_ids).each do |theme|
|
||||
builder = Stylesheet::Manager::Builder.new(
|
||||
target: target, theme: theme, manager: manager
|
||||
)
|
||||
|
||||
builder = Stylesheet::Manager::Builder.new(
|
||||
target: target, theme: theme, manager: manager
|
||||
)
|
||||
STDERR.puts "precompile target: #{target} #{builder.theme.name}"
|
||||
next if theme.component && !scss_checker.has_scss(theme.id)
|
||||
builder.compile(force: true)
|
||||
end
|
||||
else
|
||||
STDERR.puts "precompile target: #{target} #{name}"
|
||||
|
||||
next if theme.component && !scss_checker.has_scss(theme.id)
|
||||
$stderr.puts "precompile target: #{target} #{theme.name}"
|
||||
builder.compile(force: true)
|
||||
compiled << "#{target}_#{theme.id}"
|
||||
Stylesheet::Manager::Builder.new(
|
||||
target: target, theme: manager.get_theme(theme_id), manager: manager
|
||||
).compile(force: true)
|
||||
end
|
||||
end
|
||||
|
||||
theme_color_scheme = ColorScheme.find_by_id(color_scheme_id)
|
||||
theme = manager.get_theme(theme_id)
|
||||
theme_color_scheme = ColorScheme.find_by_id(color_scheme_id) || ColorScheme.base
|
||||
|
||||
[theme_color_scheme, *color_schemes].compact.uniq.each do |scheme|
|
||||
$stderr.puts "precompile target: #{COLOR_SCHEME_STYLESHEET} #{theme.name} (#{scheme.name})"
|
||||
[theme_color_scheme, *color_schemes].uniq.each do |scheme|
|
||||
STDERR.puts "precompile target: #{COLOR_SCHEME_STYLESHEET} #{name} (#{scheme.name})"
|
||||
|
||||
Stylesheet::Manager::Builder.new(
|
||||
target: COLOR_SCHEME_STYLESHEET,
|
||||
theme: theme,
|
||||
theme: manager.get_theme(theme_id),
|
||||
color_scheme: scheme,
|
||||
manager: manager
|
||||
).compile(force: true)
|
||||
@ -199,19 +193,15 @@ class Stylesheet::Manager
|
||||
def stylesheet_details(target = :desktop, media = 'all')
|
||||
target = target.to_sym
|
||||
current_hostname = Discourse.current_hostname
|
||||
is_theme_target = !!(target.to_s =~ THEME_REGEX)
|
||||
|
||||
array_cache_key = is_theme_target ?
|
||||
"array_themes_#{@theme_ids.join(",")}_#{target}_#{current_hostname}" :
|
||||
"array_#{target}_#{current_hostname}"
|
||||
|
||||
array_cache_key = "array_themes_#{@theme_ids.join(",")}_#{target}_#{current_hostname}"
|
||||
stylesheets = cache[array_cache_key]
|
||||
return stylesheets if stylesheets.present?
|
||||
|
||||
@@lock.synchronize do
|
||||
stylesheets = []
|
||||
stale_theme_ids = []
|
||||
theme_ids = is_theme_target ? @theme_ids : [nil]
|
||||
theme_ids = target.to_s =~ THEME_REGEX ? @theme_ids : [@theme_id]
|
||||
|
||||
theme_ids.each do |theme_id|
|
||||
cache_key = "path_#{target}_#{theme_id}_#{current_hostname}"
|
||||
@ -229,36 +219,25 @@ class Stylesheet::Manager
|
||||
|
||||
scss_checker = ScssChecker.new(target, stale_theme_ids)
|
||||
|
||||
if is_theme_target
|
||||
themes = load_themes(stale_theme_ids)
|
||||
themes = @theme_id.blank? ? [nil] : load_themes(stale_theme_ids)
|
||||
|
||||
themes.each do |theme|
|
||||
theme_id = theme&.id
|
||||
data = { target: target, theme_id: theme_id }
|
||||
builder = Builder.new(target: target, theme: theme, manager: self)
|
||||
is_theme = builder.is_theme?
|
||||
has_theme = builder.theme.present?
|
||||
themes.each do |theme|
|
||||
theme_id = theme&.id
|
||||
data = { target: target, theme_id: theme_id }
|
||||
builder = Builder.new(target: target, theme: theme, manager: self)
|
||||
is_theme = builder.is_theme?
|
||||
has_theme = builder.theme.present?
|
||||
|
||||
if is_theme && !has_theme
|
||||
next
|
||||
else
|
||||
next if is_theme && builder.theme&.component && !scss_checker.has_scss(theme_id)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
cache.defer_set("path_#{target}_#{theme_id}_#{current_hostname}", href)
|
||||
end
|
||||
|
||||
data[:new_href] = href
|
||||
stylesheets << data
|
||||
if is_theme && !has_theme
|
||||
next
|
||||
else
|
||||
next if is_theme && builder.theme&.component && !scss_checker.has_scss(theme_id)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
cache.defer_set("path_#{target}_#{theme_id}_#{current_hostname}", href)
|
||||
end
|
||||
else
|
||||
builder = Builder.new(target: target, manager: self)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
|
||||
cache.defer_set("path_#{target}__#{current_hostname}", href)
|
||||
|
||||
data = { target: target, new_href: href }
|
||||
data[:new_href] = href
|
||||
stylesheets << data
|
||||
end
|
||||
|
||||
|
@ -137,10 +137,6 @@ class Stylesheet::Manager::Builder
|
||||
!!(@target.to_s =~ Stylesheet::Manager::THEME_REGEX)
|
||||
end
|
||||
|
||||
def is_color_scheme?
|
||||
!!(@target.to_s == Stylesheet::Manager::COLOR_SCHEME_STYLESHEET)
|
||||
end
|
||||
|
||||
def scheme_slug
|
||||
Slug.for(ActiveSupport::Inflector.transliterate(@color_scheme.name), 'scheme')
|
||||
end
|
||||
@ -150,10 +146,8 @@ class Stylesheet::Manager::Builder
|
||||
@digest ||= begin
|
||||
if is_theme?
|
||||
theme_digest
|
||||
elsif is_color_scheme?
|
||||
color_scheme_digest
|
||||
else
|
||||
default_digest
|
||||
color_scheme_digest
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -177,7 +171,7 @@ class Stylesheet::Manager::Builder
|
||||
end
|
||||
|
||||
def theme_digest
|
||||
Digest::SHA1.hexdigest(scss_digest.to_s + color_scheme_digest.to_s + settings_digest + uploads_digest)
|
||||
Digest::SHA1.hexdigest(scss_digest.to_s + color_scheme_digest.to_s + settings_digest + plugins_digest + uploads_digest)
|
||||
end
|
||||
|
||||
# this protects us from situations where new versions of a plugin removed a file
|
||||
@ -224,10 +218,6 @@ class Stylesheet::Manager::Builder
|
||||
Digest::SHA1.hexdigest(sha1s.sort!.join("\n"))
|
||||
end
|
||||
|
||||
def default_digest
|
||||
Digest::SHA1.hexdigest "default-#{Stylesheet::Manager.last_file_updated}-#{plugins_digest}"
|
||||
end
|
||||
|
||||
def color_scheme_digest
|
||||
cs = @color_scheme || theme&.color_scheme
|
||||
|
||||
|
@ -96,7 +96,11 @@ module Stylesheet
|
||||
targets = target ? [target] : ["desktop", "mobile", "admin"]
|
||||
Stylesheet::Manager.clear_core_cache!(targets)
|
||||
message = targets.map! do |name|
|
||||
Stylesheet::Manager.new.stylesheet_data(name.to_sym)
|
||||
msgs = []
|
||||
active_themes.each do |theme_id|
|
||||
msgs << Stylesheet::Manager.new(theme_id: theme_id).stylesheet_data(name.to_sym)
|
||||
end
|
||||
msgs
|
||||
end.flatten!
|
||||
MessageBus.publish '/file-change', message
|
||||
end
|
||||
@ -110,7 +114,11 @@ module Stylesheet
|
||||
targets.push(plugin_name)
|
||||
end
|
||||
message = targets.map! do |name|
|
||||
Stylesheet::Manager.new.stylesheet_data(name.to_sym)
|
||||
msgs = []
|
||||
active_themes.each do |theme_id|
|
||||
msgs << Stylesheet::Manager.new(theme_id: theme_id).stylesheet_data(name.to_sym)
|
||||
end
|
||||
msgs
|
||||
end.flatten!
|
||||
MessageBus.publish '/file-change', message
|
||||
end
|
||||
@ -135,5 +143,9 @@ module Stylesheet
|
||||
end
|
||||
end
|
||||
|
||||
def active_themes
|
||||
@active_themes ||= Theme.user_selectable.pluck(:id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user