mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 02:05:49 +08:00
Precompile core stylesheets independently of themes
This commit is contained in:

committed by
Alan Guo Xiang Tan

parent
d82c58e6cc
commit
99d259d39b
@ -42,6 +42,17 @@ 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, :name, :color_scheme_id)
|
||||
themes << nil
|
||||
|
||||
@ -49,8 +60,7 @@ class Stylesheet::Manager
|
||||
color_schemes << ColorScheme.find_by(id: SiteSetting.default_dark_mode_color_scheme_id)
|
||||
color_schemes = color_schemes.compact.uniq
|
||||
|
||||
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)
|
||||
targets = [:desktop_theme, :mobile_theme]
|
||||
|
||||
themes.each do |id, name, color_scheme_id|
|
||||
theme_id = id || SiteSetting.default_theme_id
|
||||
@ -193,15 +203,19 @@ 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 = target.to_s =~ THEME_REGEX ? @theme_ids : [@theme_id]
|
||||
theme_ids = is_theme_target ? @theme_ids : [nil]
|
||||
|
||||
theme_ids.each do |theme_id|
|
||||
cache_key = "path_#{target}_#{theme_id}_#{current_hostname}"
|
||||
@ -219,25 +233,36 @@ class Stylesheet::Manager
|
||||
|
||||
scss_checker = ScssChecker.new(target, stale_theme_ids)
|
||||
|
||||
themes = @theme_id.blank? ? [nil] : load_themes(stale_theme_ids)
|
||||
if is_theme_target
|
||||
themes = 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)
|
||||
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
|
||||
end
|
||||
else
|
||||
builder = Builder.new(target: target, manager: self)
|
||||
builder.compile unless File.exists?(builder.stylesheet_fullpath)
|
||||
href = builder.stylesheet_path(current_hostname)
|
||||
|
||||
data[:new_href] = href
|
||||
cache.defer_set("path_#{target}__#{current_hostname}", href)
|
||||
|
||||
data = { target: target, new_href: href }
|
||||
stylesheets << data
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user