-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirects.rb
43 lines (33 loc) · 1.1 KB
/
redirects.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Jekyll
# STEP 1: Trigger page generation based on redirects.yml
class RedirectsBuilder < Generator
safe true
def generate(site)
# Get all redirections to work with
site.data['redirection'].each do |r|
# Allow for multiple "from" URLS, convert singles into array
Array(r['from']).each do |from|
# Create and add redirects to site pages
new_redirect = RedirectPage.new(
site,
site.source,
from )
new_redirect.data['permalink'] = from
new_redirect.data['source_url'] = r['to']
site.pages << new_redirect
end # End from Array each
end # End site.data each
end # End def generate()
end # End Builder Class
# STEP 2: Generate actual page using data from redirects.yml
class RedirectPage < Page
def initialize(site, base, dir)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'redirect.html')
end # End initialize
end # End Page Class
end # End Jekyll