FEATURE: Improve wizard font selection and set Inter as default font for new sites (#30974)

This commit narrows down the list of fonts we offer
in our setup wizard and simplifies things to only
show a single font dropdown. This selection will then
set the `base_font` and `heading_font` site setting to
the same value.

For existing sites that may have set different values,
we will still show 2 dropdowns when visiting the wizard.

We are also changing our default font to the more modern
selection Inter, replacing Arial. Arial is very dependent
on system installed fonts, whereas Inter we can package
to everyone in Discourse.

Finally, for existing sites that have not changed their default
from Arial, we will keep that value via a migration so we do
not surprise site owners with a completely new font.
This commit is contained in:
Martin Brennan
2025-01-27 11:29:55 +10:00
committed by GitHub
parent 08ce000647
commit 78a857931c
12 changed files with 167 additions and 34 deletions

View File

@ -2,6 +2,8 @@
class Wizard
class Builder
WIZARD_FONTS = %w[lato inter montserrat open_sans poppins roboto]
def initialize(user)
@wizard = Wizard.new(user)
end
@ -165,28 +167,50 @@ class Wizard
themes.add_choice(t[:id], data: { colors: t[:colors] })
end
body_font =
step.add_field(
id: "body_font",
type: "dropdown",
value: SiteSetting.base_font,
show_in_sidebar: true,
)
if SiteSetting.base_font != SiteSetting.heading_font
body_font =
step.add_field(
id: "body_font",
type: "dropdown",
value: SiteSetting.base_font,
show_in_sidebar: true,
)
heading_font =
step.add_field(
id: "heading_font",
type: "dropdown",
value: SiteSetting.heading_font,
show_in_sidebar: true,
)
heading_font =
step.add_field(
id: "heading_font",
type: "dropdown",
value: SiteSetting.heading_font,
show_in_sidebar: true,
)
else
site_font =
step.add_field(
id: "site_font",
type: "dropdown",
value: SiteSetting.base_font,
show_in_sidebar: true,
)
end
allowed_fonts = WIZARD_FONTS
allowed_fonts << SiteSetting.base_font if !allowed_fonts.include?(SiteSetting.base_font)
if !allowed_fonts.include?(SiteSetting.heading_font)
allowed_fonts << SiteSetting.heading_font
end
DiscourseFonts
.fonts
.sort_by { |f| f[:name] }
.select do |font|
# We only want to display certain fonts in the wizard, others will be accessible
# in site settings.
allowed_fonts.include?(font[:key])
end
.sort_by { |font| font[:name] }
.each do |font|
body_font.add_choice(font[:key], label: font[:name])
heading_font.add_choice(font[:key], label: font[:name])
body_font&.add_choice(font[:key], label: font[:name])
heading_font&.add_choice(font[:key], label: font[:name])
site_font&.add_choice(font[:key], label: font[:name])
end
current =
@ -217,8 +241,13 @@ class Wizard
step.add_field(id: "styling_preview", type: "styling-preview")
step.on_update do |updater|
updater.update_setting(:base_font, updater.fields[:body_font])
updater.update_setting(:heading_font, updater.fields[:heading_font])
if updater.fields[:site_font].present?
updater.update_setting(:base_font, updater.fields[:site_font])
updater.update_setting(:heading_font, updater.fields[:site_font])
else
updater.update_setting(:base_font, updater.fields[:body_font])
updater.update_setting(:heading_font, updater.fields[:heading_font])
end
top_menu = SiteSetting.top_menu_map
if !updater.fields[:homepage_style].include?("categories") &&