class JekyllRedirectFrom::RedirectPage
Specialty page which implements the redirect path logic
Constants
- DEFAULT_DATA
Public Class Methods
from_paths(site, from, to)
click to toggle source
Creates a new RedirectPage
instance from a source path and redirect path
site - The Site object from - the (URL) path, relative to the site root to redirect from to - the relative path or URL which the page should redirect to
# File lib/jekyll-redirect-from/redirect_page.rb, line 19 def self.from_paths(site, from, to) page = RedirectPage.new(site, site.source, "", "redirect.html") page.set_paths(from, to) page end
redirect_from(doc, path)
click to toggle source
Creates a new RedirectPage
instance from the path to the given doc
# File lib/jekyll-redirect-from/redirect_page.rb, line 26 def self.redirect_from(doc, path) RedirectPage.from_paths(doc.site, path, doc.url) end
redirect_to(doc, path)
click to toggle source
Creates a new RedirectPage
instance from the doc to the given path
# File lib/jekyll-redirect-from/redirect_page.rb, line 31 def self.redirect_to(doc, path) RedirectPage.from_paths(doc.site, doc.url, path) end
Public Instance Methods
read_yaml(_base, _name, _opts = {})
click to toggle source
Overwrite the default read_yaml
method since the file doesn't exist
# File lib/jekyll-redirect-from/redirect_page.rb, line 36 def read_yaml(_base, _name, _opts = {}) self.content = self.output = "" self.data ||= DEFAULT_DATA.dup end
redirect_from()
click to toggle source
# File lib/jekyll-redirect-from/redirect_page.rb, line 57 def redirect_from data["redirect"]["from"] if data["redirect"] end
redirect_to()
click to toggle source
# File lib/jekyll-redirect-from/redirect_page.rb, line 61 def redirect_to data["redirect"]["to"] if data["redirect"] end
set_paths(from, to)
click to toggle source
Helper function to set the appropriate path metadata
from - the relative path to the redirect page to - the relative path or absolute URL to the redirect target
# File lib/jekyll-redirect-from/redirect_page.rb, line 45 def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from, "to" => %r!^https?://!.match?(to) ? to : absolute_url(to), } ) end
Private Instance Methods
context()
click to toggle source
# File lib/jekyll-redirect-from/redirect_page.rb, line 67 def context JekyllRedirectFrom::Context.new(site) end