Class: Seo::LinkSanitizer

Inherits:
BaseService show all
Defined in:
app/services/seo/link_sanitizer.rb

Overview

This class takes a single link and sanitize it for the purpose of hosting it
on warmlyyours.com, localized links are delocalized with {locale} (a Liquid variable)
and if relative is specified then the hostname www.warmlyyours.com is ommitted

Defined Under Namespace

Classes: Result

Constant Summary collapse

WY_HOSTNAME =
'www.warmlyyours.com'
HOSTNAME_IN_PATH =
%r{\A(www\.)?(\w+\.[a-z]{2,3})/?}i

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(href, relative: false) ⇒ Seo::LinkSanitizer::Result

Produces a canonical WarmlyYours URL from an input href, applying locale, hostname,
scheme, and path normalizations so the result is suitable for warmlyyours.com.

Parameters:

  • href (String)
    • The input URL or path to sanitize; blank or anchor-only values are handled.
  • relative (Boolean) (defaults to: false)
    • If true, return a path relative to the WarmlyYours host.

Returns:

  • (Seo::LinkSanitizer::Result)

    Result with out containing the sanitized URL when successful.
    Possible status values:
    :href_missing (blank input), :not_applicable (anchor-only #...), :unparsable (could not parse),
    :incompatible_scheme (non-http scheme). When relative is true, out is returned relative to "https://www.warmlyyours.com".



23
24
25
26
27
28
29
30
31
# File 'app/services/seo/link_sanitizer.rb', line 23

def process(href, relative: false)
  href = href.to_s
  return Result.new(status: :href_missing) if href.blank?
  return Result.new(status: :not_applicable) if href.start_with?('#')

  href = href.dup
  logger.info "Processing #{href}"
  process_parsed_href(href, relative: relative)
end