From 3c114729b0e645d17e4753718213ec1650aa4d8b Mon Sep 17 00:00:00 2001 From: Achilleas Pipinellis Date: Tue, 9 Feb 2021 09:11:01 +0000 Subject: Implement YAML redirects mechanism Keep track of the Pages redirects in a YAML file and use a Raketask to populate _redirects. --- Rakefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Rakefile') diff --git a/Rakefile b/Rakefile index ecc08dfb2..d714ab750 100644 --- a/Rakefile +++ b/Rakefile @@ -254,3 +254,18 @@ task :symlink_readmes do end end +desc 'Create the _redirects file' +task :redirects do + redirects_yaml = YAML.load_file('content/_data/redirects.yaml') + redirects_file = 'content/_redirects' + + # Remove _redirects before populating it + File.delete(redirects_file) if File.exists?(redirects_file) + + # Iterate over each entry and append to _redirects + redirects_yaml.fetch('redirects').each do |redirect| + File.open(redirects_file, 'a') do |f| + f.puts "#{redirect.fetch('from')} #{redirect.fetch('to')} 302" + end + end +end -- cgit v1.2.3