Class: Locomotive::Steam::Middlewares::EncodedLinkRedirection

Inherits:
ThreadSafe
  • Object
show all
Includes:
Concerns::Helpers
Defined in:
lib/locomotive/steam/middlewares/encoded_link_redirection.rb

Overview

Redirect to the resource (page, templatized page with a content entry) based on the encoded link in the url. The link is encoded by the UrlPicker component (engine).

For SEO purpose, the encoded link shouldn’t be shared. It’s just for internal purposes.

Example:

/_locomotive-link/eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0

will redirect (302) to www.nocoffee.fr

Constant Summary collapse

PATH_REGEXP =
/\/_locomotive-link\/(?<link>[^\"]+)/mo.freeze

Constants included from Concerns::Helpers

Concerns::Helpers::CACHE_HEADERS, Concerns::Helpers::HTML_CONTENT_TYPE, Concerns::Helpers::HTML_MIME_TYPES

Instance Attribute Summary

Attributes inherited from ThreadSafe

#env

Instance Method Summary collapse

Methods included from Concerns::Helpers

#html?, #inject_cookies, #json?, #log, #make_local_path, #modify_path, #mounted_on, #redirect_to, #render_response

Methods inherited from ThreadSafe

#call, #decorate_entry, #default_liquid_context, #default_locale, #liquid_assigns, #live_editing?, #locale, #locales, #merge_with_params, #next, #page, #params, #path, #repositories, #request, #services, #session, #site

Instance Method Details

#_callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/locomotive/steam/middlewares/encoded_link_redirection.rb', line 22

def _call
  if env['PATH_INFO'] =~ PATH_REGEXP
    resource = url_finder.decode_link($~[:link])

    # set the locale
    if resource && resource['locale']
      services.locale = 'fr'
    end

    link, _ = url_finder.url_for(resource)

    redirect_to link, 302
  end
end