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
44
45
46
47
48
49
|
# File 'lib/jekyll/commands/migrate_permalink.rb', line 19
def process(args, opts)
Jekyll.logger.adjust_verbosity(opts)
options = configuration_from_options(opts)
site = Jekyll::Site.new(options)
site.reset
site.read
site.posts.docs.each do |post|
content = File.read(post.path, Utils.merged_file_read_opts(site, options))
if content =~ Document::YAML_FRONT_MATTER_REGEXP
content = $POSTMATCH
frontmatter = SafeYAML.load(Regexp.last_match(1))
end
if opts["strategy"] == "retain"
frontmatter["permalink"] = post.url
else
if frontmatter["redirect_from"].is_a? Array
frontmatter["redirect_from"].push(post.url)
else
frontmatter["redirect_from"] = [post.url]
end
end
output = "#{frontmatter.to_yaml}---\n\n#{content}"
File.write(post.path, output, :mode => "w")
end
end
|