Class: Seo::SiteMapHistoryRedirect

Inherits:
Object
  • Object
show all
Defined in:
app/services/seo/site_map_history_redirect.rb

Overview

Resolves an incoming (locale, path) that 404'd against SiteMap URL history
and returns the page's current path so the caller can serve a 301.

This is the request-time half of the self-healing-rename design — see
doc/tasks/202606042115_SITEMAP_URL_HISTORY.md. When the sitemap generator
renames a page it records the old path in SiteMapPathHistory; a later request
to that old URL lands here (via Controllers::ErrorRendering#render_404) and is
301'd to the page's current path.

Class Method Summary collapse

Class Method Details

.resolve(locale:, path:) ⇒ String?

Returns the page's current locale-less path, or nil if there's
no history match (or redirecting would be unsafe).

Parameters:

  • locale (String)

    e.g. "en-US"

  • path (String)

    the locale-stripped request path, e.g. "/radiant-panel/ember/flex"

Returns:

  • (String, nil)

    the page's current locale-less path, or nil if there's
    no history match (or redirecting would be unsafe)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/seo/site_map_history_redirect.rb', line 16

def self.resolve(locale:, path:)
  return nil if locale.blank? || path.blank?

  history = SiteMapPathHistory.find_by(locale: locale, path: path)
  return nil unless history

  target = history.site_map
  return nil unless target&.active?
  return nil if target.path.blank? || target.path == path

  # Path-reuse guard: never redirect a path that is itself a live page.
  return nil if SiteMap.active.exists?(locale: locale, path: path)

  target.path
end