Class: Seo::FaInlineSvgRestorer
- Inherits:
-
BaseService
- Object
- BaseService
- Seo::FaInlineSvgRestorer
- Defined in:
- app/services/seo/fa_inline_svg_restorer.rb
Overview
Converts Font Awesome inline SVGs back to tags in HTML content.
The CRM editor uses FA's SVG+JS engine which replaces
with .
The www frontend uses CSS Web Fonts, which expects tags. This service
restores the natural form so icons render correctly on both sides.
Also restores missing icons inside callout-facts headings (h4/h5)
that lost their icon when the SVG was removed without adding back the .
Usage:
result = Seo::FaInlineSvgRestorer.new.process(html_string)
result.html_out # cleaned HTML
result.changed? # whether any replacements were made
result.svg_count # number of SVGs replaced
result.icon_count # number of missing callout icons restored
Defined Under Namespace
Classes: Result
Constant Summary collapse
- PREFIX_MAP =
{ "fas" => "fa-solid", "far" => "fa-regular", "fal" => "fa-light", "fat" => "fa-thin", "fad" => "fa-duotone", "fass" => "fa-sharp fa-solid", "fasr" => "fa-sharp fa-regular", "fasl" => "fa-sharp fa-light", }.freeze
- CALLOUT_FACTS_ICON =
"fa-list-check"
Instance Method Summary collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#process(html_fragment) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/seo/fa_inline_svg_restorer.rb', line 38 def process(html_fragment) return Result.new(html_out: html_fragment) if html_fragment.blank? return Result.new(html_out: html_fragment) unless html_fragment.include?("svg-inline--fa") || html_fragment.include?("callout-facts") doc = Nokogiri::HTML(html_fragment) svg_count = replace_inline_svgs(doc) icon_count = restore_callout_facts_icons(doc) if svg_count > 0 || icon_count > 0 html_out = doc.at("body")&.inner_html.presence&.html_safe Result.new(html_out: html_out, changed: true, svg_count: svg_count, icon_count: icon_count) else Result.new(html_out: html_fragment) end end |