File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- # This plugin allows using front matter variables in permalinks.
3+ # This plugin allows using front matter variables in permalinks and redirect_from .
44# For example: permalink: /sips/:number will use the 'number' front matter field.
55
66Jekyll ::Hooks . register :site , :after_init do
@@ -10,3 +10,18 @@ def number
1010 end
1111 end
1212end
13+
14+ # Expand :number and :title in redirect_from values
15+ Jekyll ::Hooks . register :documents , :pre_render do |doc |
16+ next unless doc . data [ "redirect_from" ]
17+
18+ redirects = doc . data [ "redirect_from" ]
19+ redirects = [ redirects ] unless redirects . is_a? ( Array )
20+
21+ doc . data [ "redirect_from" ] = redirects . map do |redirect |
22+ result = redirect
23+ result = result . gsub ( ":number" , doc . data [ "number" ] . to_s ) if doc . data [ "number" ]
24+ result = result . gsub ( ":title" , Jekyll ::Utils . slugify ( doc . data [ "title" ] ) ) if doc . data [ "title" ]
25+ result
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments