41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/jekyll/taxonomy_redirects.rb', line 41
def generate(site)
cfg = site.config["taxonomy_redirects"] || {}
roots = Array(cfg["roots"])
maps = Array(cfg["maps"])
emit_canonical = cfg.key?("emit_canonical") ? !!cfg["emit_canonical"] : true
roots.each do |r|
from = trim_slashes(r["from"].to_s)
to = ensure_trailing_slash(r["to"].to_s)
next if from.empty? || to.empty?
site.static_files << RedirectStaticFile.new(site, from, "index.html", to, emit_canonical: emit_canonical)
end
maps.each do |m|
type = m["type"].to_s
from = trim_slashes(m["from"].to_s)
to = trim_slashes(m["to"].to_s)
next if type.empty? || from.empty? || to.empty?
slugs = case type
when "category" then site.categories.keys
when "tag" then site.tags.keys
else []
end
slugs.each do |slug|
from_dir = File.join(from, slug)
dest_url = "/" + File.join(to, slug, "")
site.static_files << RedirectStaticFile.new(site, from_dir, "index.html", dest_url, emit_canonical: emit_canonical)
end
end
end
|