namespace :router_data do
  task export_multipart_redirects: [:environment] do
    artefacts = Artefact
      .multipart_formats
      .archived
      .with_redirect
      .order(slug: :ASC)
      .pluck(:slug, :redirect_url)

    filename = "/tmp/publisher_router_data_export.csv"

    puts "Writing file with #{artefacts.count} redirects"

    csv = "Source,Destination,Type\n"
    csv << artefacts
      .map { |arr| "/#{arr[0]},#{arr[1]},prefix" }
      .join("\n")

    File.write(filename, csv)

    puts "#{filename}"
    puts "Complete."
  end
end

namespace :router_data do
  task export_multipart_redirects: [:environment] do
    artefacts = Artefact
      .multipart_formats
      .archived
      .with_redirect
      .order(slug: :ASC)
      .pluck(:slug, :redirect_url)

    filename = "/tmp/publisher_router_data_export.csv"

    puts "Writing file with #{artefacts.count} redirects"

    csv = "Source,Destination,Type\n"
    csv << artefacts
      .map { |arr| "/#{arr[0]},#{arr[1].gsub(/#.*/, '')},prefix" }
      .join("\n")

    File.write(filename, csv)

    puts "#{filename}"
    puts "Complete."
  end
end

Remove segments from mulitpart redirects
Remove segments from mulitpart redirects

Publisher currently allows segment redirects within its' GUI. For our
temporary task to export multipart redirects to router-data we will be
removing all segment redirects and only redirect to the top of the page.
