Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (36 sloc) 1.348 kb
8931ea5 @zachwill Add _plugins directory
authored
1 module Jekyll
2
3 # The redirect page creates a simple page that refreshes a user from a URL alias to an existing post.
4 # Redirects are only generated if there is a "redirects" parameter _config.yml
5
6 class Redirects < Generator
7
8 safe true
9 priority :low
10
11 # only process redirects if it's set in the config file
12 def generate(site)
13 generate_redirects(site) if (site.config['redirects'])
14 end
15
16 # find all posts with a redirect property and create a new page for each entry
17 def generate_redirects(site)
18 site.posts.select{|x| x.data.key? 'redirects' }.each do |p|
19 p.data['redirects'].each do |r|
c8c4a6b @zachwill Update redirects plugin
authored
20 redirect = RedirectPage.new(site, site.source, r, p.permalink)
8931ea5 @zachwill Add _plugins directory
authored
21 redirect.render(site.layouts, site.site_payload)
22 redirect.write(site.dest)
23 site.pages << redirect
24 end
25 end
26 end
27
28 end
29
60e65d1 @zachwill Update post URL
authored
30 # a class for generating the redirect pages.
8931ea5 @zachwill Add _plugins directory
authored
31 class RedirectPage < Page
32
33 def initialize(site, base, path, destination)
34
35 @site = site
36 @base = base
37 @dir = path
38 @name = 'index.html'
39 self.process(@name)
40
41 # Read the YAML data from the layout page.
42 self.read_yaml(File.join(base, '_layouts'), 'redirect.html')
43 self.data['source_url'] = destination
44
45 end
46
47 end
48
49 end
Something went wrong with that request. Please try again.