Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/add_redirects.rb
1677 views
1
# frozen_string_literal: true
2
3
BASE_REF = ARGV[0]
4
redirects = `git diff --name-status -C #{BASE_REF}`.split(/\n/).select { |x| x[0] == 'R' }
5
6
redirects.each do |x|
7
_, redir_from, redir_to = x.split(/\t/)
8
redir_from = redir_from.gsub(/.md/, '').gsub(/.html/, '')
9
10
puts "Adding redirect to #{redir_to}"
11
f = File.open(redir_to, 'r')
12
contents = f.read.split(/\n/)
13
contents = contents[0..0] + ['redirect_from:', "- /#{redir_from}"] + contents[1..]
14
f.close
15
16
File.write(redir_to, contents.join("\n"))
17
end
18
19