DEV: Delete symlink when DiscourseFont path changes (#30294)

When adding new fonts to our discourse-fonts gem,
you may want to test these changes locally using the
`path` option of the gem line in bundler.

However we set a symlink for the fonts dir for public/fonts,
which does not get updated if the gem path changes. This
fix checks if the current symlink resolved path is equal to
the DiscourseFont gem path, and if not deletes + recreates it.
This commit is contained in:
Martin Brennan 2024-12-17 13:57:03 +10:00 committed by GitHub
parent c1c7ea8959
commit 0705857a47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -235,7 +235,11 @@ module Discourse
# Use discourse-fonts gem to symlink fonts and generate .scss file
fonts_path = File.join(config.root, "public/fonts")
if !File.exist?(fonts_path) || File.realpath(fonts_path) != DiscourseFonts.path_for_fonts
puts "Symlinking fonts from discourse-fonts gem"
File.delete(fonts_path) if File.exist?(fonts_path)
Discourse::Utils.atomic_ln_s(DiscourseFonts.path_for_fonts, fonts_path)
end
require "stylesheet/manager"
require "svg_sprite"