class JekyllRedirectFrom::RedirectPage

Public Class Methods

new(site, base, dir, name) click to toggle source

Initialize a new RedirectPage.

site - The Site object. base - The String path to the source. dir - The String path between the source and the file. name - The String filename of the file.

# File lib/jekyll-redirect-from/redirect_page.rb, line 10
def initialize(site, base, dir, name)
  @site = site
  @base = base
  @dir  = dir
  @name = name

  self.process(name)
  self.data = {}

  data.default_proc = proc do |_, key|
    site.frontmatter_defaults.find(File.join(dir, name), type, key)
  end

  Jekyll::Hooks.trigger :pages, :post_init, self if JekyllRedirectFrom.jekyll_3?
end

Public Instance Methods

generate_redirect_content(item_url) click to toggle source
# File lib/jekyll-redirect-from/redirect_page.rb, line 26
    def generate_redirect_content(item_url)
      self.output = self.content = <<-EOF
<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting…</title>
<link rel="canonical" href="#{item_url}">
<meta http-equiv="refresh" content="0; url=#{item_url}">
<h1>Redirecting…</h1>
<a href="#{item_url}">Click here if you are not redirected.</a>
<script>location="#{item_url}"</script>
EOF
    end