module Middleman::Redirects
Constants
- BLANK_RE
- VERSION
Attributes
match_trailing_slashes[RW]
Public Class Methods
read_redirects()
click to toggle source
# File lib/middleman/redirects.rb, line 54 def self.read_redirects @mtime = self.redirects_file_path.mtime @redirects = {} self.redirects_file_path.each_line.map do |line| next if line =~ /^#/ # ignore comments next if line.empty? next if BLANK_RE === line parts = line.split source = URI.parse(parts[0]) destination = URI.parse(parts[1]) redirect_code = if parts[2] =~ /permanent/ 301 else 302 end # don't allow a single / or * as source next if source.path == '/' next if source.path == '.*' next if source.path == '*' # invalid @redirects[source.to_s] = [destination.to_s, redirect_code] end autogenerated_redirects = {} # duplicate redirect so it also matches URIs with a trailing slash if self.match_trailing_slashes @redirects.each do |source, destination_and_code| next if source[-1] == '/' autogenerated_redirects["#{source}/"] = destination_and_code end end @redirects.merge!(autogenerated_redirects) end
redirects()
click to toggle source
# File lib/middleman/redirects.rb, line 46 def self.redirects if self.redirects_file_path.mtime != @mtime read_redirects else @redirects end end
redirects_file_path()
click to toggle source
# File lib/middleman/redirects.rb, line 42 def self.redirects_file_path @redirects_file_path end
redirects_file_path=(v)
click to toggle source
# File lib/middleman/redirects.rb, line 38 def self.redirects_file_path=(v) @redirects_file_path = v end