diff --git a/plugins/pageless_redirects.rb b/plugins/pageless_redirects.rb new file mode 100755 index 0000000000..a5c6bda016 --- /dev/null +++ b/plugins/pageless_redirects.rb @@ -0,0 +1,166 @@ +# Pageless Redirect Generator +# +# Generates redirect pages based on YAML or htaccess style redirects +# +# To generate redirects create _redirects.yml, _redirects.htaccess, and/or _redirects.json in the Jekyll root directory +# both follow the pattern alias, final destination. +# +# Example _redirects.yml +# +# initial-page : /destination-page +# other-page : http://example.org/destination-page +# "another/page" : /destination-page +# +# Result: +# Requests to /initial-page are redirected to /destination-page +# Requests to /other-page are redirected to http://example.org/destination-page +# Requests to /another/page are redirected to /destination-page +# +# +# Example _redirects.htaccess +# +# Redirect /some-page /destination-page +# Redirect 301 /different-page /destination-page +# Redirect cool-page http://example.org/destination-page +# +# Result: +# Requests to /some-page are redirected to /destination-page +# Requests to /different-page are redirected to /destination-page +# Requests to /cool-page are redirected to http://example.org/destination-page +# +# +# Example _redirects.json +# +# { +# "some-page" : "/destination-page", +# "yet-another-page" : "http://example.org/destination-page", +# "ninth-page" : "/destination-page" +# } +# +# Result: +# Requests to /some-page are redirected to /destination-page +# Requests to /yet-another-page are redirected to http://example.org/destination-page +# Requests to /ninth-page are redirected to /destination-page +# +# +# Author: Nick Quinlan +# Site: http://nicholasquinlan.com +# Plugin Source: https://github.com/nquinlan/jekyll-pageless-redirects +# Plugin License: MIT +# Plugin Credit: This plugin borrows heavily from alias_generator (http://github.com/tsmango/jekyll_alias_generator) by Thomas Mango (http://thomasmango.com) + +require 'json' + +module Jekyll + + class PagelessRedirectGenerator < Generator + + def generate(site) + @site = site + + process_yaml + process_htaccess + process_json + end + + def process_yaml + file_path = @site.source + "/_redirects.yml" + if File.exists?(file_path) + YAML.load_file(file_path, :safe => true).each do | new_url, old_url | + generate_aliases( old_url, new_url ) + end + end + end + + def process_htaccess + file_path = @site.source + "/_redirects.htaccess" + if File.exists?(file_path) + # Read the file line by line pushing redirects to the redirects array + file = File.new(file_path, "r") + while (line = file.gets) + # Match the line against a regex, if it matches push it to the object + /^Redirect(\s+30[1237])?\s+(.+?)\s+(.+?)$/.match(line) { | matches | + generate_aliases( matches[3], matches[2]) + } + end + file.close + end + end + + def process_json + file_path = @site.source + "/_redirects.json" + if File.exists?(file_path) + file = File.new(file_path, "r") + content = JSON.parse(file.read) + content.each do |new_url, old_url| + generate_aliases(old_url, new_url) + end + file.close + end + end + + def generate_aliases(destination_path, aliases) + alias_paths ||= Array.new + alias_paths << aliases + alias_paths.compact! + + alias_paths.flatten.each do |alias_path| + alias_path = alias_path.to_s + + alias_dir = File.extname(alias_path).empty? ? alias_path : File.dirname(alias_path) + alias_file = File.extname(alias_path).empty? ? "index.html" : File.basename(alias_path) + + fs_path_to_dir = File.join(@site.dest, alias_dir) + alias_index_path = File.join(alias_dir, alias_file) + + FileUtils.mkdir_p(fs_path_to_dir) + + File.open(File.join(fs_path_to_dir, alias_file), 'w') do |file| + puts "generating redirect for " + alias_path + " to " + destination_path + file.write(alias_template(destination_path)) + end + + (alias_index_path.split('/').size + 1).times do |sections| + @site.static_files << Jekyll::PagelessRedirectFile.new(@site, @site.dest, alias_index_path.split('/')[0, sections].join('/'), '') + end + end + end + + def alias_template(destination_path) + <<-EOF + + +
+Redirecting...
+ + + + + EOF + end + end + + class PagelessRedirectFile < StaticFile + require 'set' + + def destination(dest) + File.join(dest, @dir) + end + + def modified? + return false + end + + def write(dest) + return true + end + end +end diff --git a/source/_redirects.htaccess b/source/_redirects.htaccess new file mode 100644 index 0000000000..06806d7e1f --- /dev/null +++ b/source/_redirects.htaccess @@ -0,0 +1,157 @@ + +####### +# +# /API_Reference > Customer Subuser API +# +####### +Redirect 301 /API_Reference/Customer_Subuser_API/event_notification_url.html https://sendgrid.com/docs/API_Reference/Customer_Subuser_API/v1_(deprecated)/event_notification_url.html + +####### +# +# /API_Reference > Reseller API +# +####### +Redirect 301 /API_Reference/Reseller_API/billing_retrieving_as_you_go_usage.html https://sendgrid.com/docs/API_Reference/Reseller_API/v1_(deprecated)/billing_retrieving_as_you_go_usage.html +Redirect 301 /API_Reference/Reseller_API/billing_retrieving_end_users_invoices_usage.html https://sendgrid.com/docs/API_Reference/Reseller_API/v1_(deprecated)/billing_retrieving_end_users_invoices_usage.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_account_limits.html https://sendgrid.com/docs/API_Reference/Reseller_API/v1_(deprecated)/customer_account_limits.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_apps.html https://sendgrid.com/docs/API_Reference/Reseller_API/v1_(deprecated)/customer_subuser_apps_filters.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_automatic_login.html https://sendgrid.com/docs/API_Reference/Reseller_API/v1_(deprecated)/automatic_login.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_bounces.htm https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_bounces.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_event_notification_url.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_event_notification_url.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_invalid_emails.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_invalid_emails.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_monitor_outgoing_email.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_monitor_outgoing_email.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_parse_settings.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_parse_settings.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_spam_reports.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_spam_reports.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_statistics.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_statistics.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_timezone.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_timezone.html +Redirect 301 /API_Reference/Reseller_API/customer_subuser_unsubscribes.html https://sendgrid.com/docs/API_Reference/Reseller_API/Reseller_Customer_Subuser_API/customer_subuser_unsubscribes.html + +####### +# +# /docs/Apps - moved to User Guide - originally sendgrid.com/docs/Apps/ +# +####### +Redirect 301 /Apps/index.html https://sendgrid.com/docs/User_Guide/Apps/index.html +Redirect 301 /Apps/address_whitelisting.html https://sendgrid.com/docs/User_Guide/Apps/address_whitelisting.html +Redirect 301 /Apps/bcc.html https://sendgrid.com/docs/User_Guide/Apps/bcc.html +Redirect 301 /Apps/bypass_list_management.html https://sendgrid.com/docs/User_Guide/Apps/bypass_list_management.html +Redirect 301 /Apps/click_tracking.html https://sendgrid.com/docs/User_Guide/Apps/click_tracking.html +Redirect 301 /Apps/domain_keys.html https://sendgrid.com/docs/User_Guide/Apps/domain_keys.html +Redirect 301 /Apps/dkim.html https://sendgrid.com/docs/User_Guide/Apps/dkim.html +Redirect 301 /Apps/email_templates.html https://sendgrid.com/docs/User_Guide/Apps/email_templates.html +Redirect 301 /Apps/event_notification.html https://sendgrid.com/docs/User_Guide/Apps/event_notification.html +Redirect 301 /Apps/footer.html https://sendgrid.com/docs/User_Guide/Apps/footer.html +Redirect 301 /Apps/forward_spam.html https://sendgrid.com/docs/User_Guide/Apps/forward_spam.html +Redirect 301 /Apps/google_analytics.html https://sendgrid.com/docs/User_Guide/Apps/google_analytics.html +Redirect 301 /Apps/gravatar.html https://sendgrid.com/docs/User_Guide/Apps/gravatar.html +Redirect 301 /Apps/new_relic.html https://sendgrid.com/docs/User_Guide/Apps/new_relic.html +Redirect 301 /Apps/open_tracking.html https://sendgrid.com/docs/User_Guide/Apps/open_tracking.html +Redirect 301 /Apps/sendwithus.html https://sendgrid.com/docs/User_Guide/Apps/sendwithus.html +Redirect 301 /Apps/spam_checker.html https://sendgrid.com/docs/User_Guide/Apps/spam_checker.html +Redirect 301 /Apps/subscription_tracking.html https://sendgrid.com/docs/User_Guide/Apps/subscription_tracking.html +Redirect 301 /Apps/template_engine.html https://sendgrid.com/docs/User_Guide/Apps/template_engine.html + +####### +# +# /docs/Code_Examples - moved to User Guide - originally sendgrid.com/docs/Code_Examples +# +####### +Redirect 301 /Code_Examples/index.html https://sendgrid.com/docs/Integrate/Code_Examples/index.html +Redirect 301 /Code_Examples/index.htmlhttps://sendgrid.com/docs/Integrate/Code_Examples/index.html +Redirect 301 /Code_Examples/csharp.html https://sendgrid.com/docs/Integrate/Code_Examples/csharp.html +Redirect 301 /Code_Examples/go.html https://sendgrid.com/docs/Integrate/Code_Examples/go.html +Redirect 301 /Code_Examples/ios.html https://sendgrid.com/docs/Integrate/Code_Examples/ios.html +Redirect 301 /Code_Examples/java.html https://sendgrid.com/docs/Integrate/Code_Examples/java.html +Redirect 301 /Code_Examples/nodejs.html https://sendgrid.com/docs/Integrate/Code_Examples/nodejs.html +Redirect 301 /Code_Examples/perl.htmlhttps://sendgrid.com/docs/Integrate/Code_Examples/perl.html +Redirect 301 /Code_Examples/php.html https://sendgrid.com/docs/Integrate/Code_Examples/php.html +Redirect 301 /Code_Examples/python.html https://sendgrid.com/docs/Integrate/Code_Examples/python.html +Redirect 301 /Code_Examples/ruby.html https://sendgrid.com/docs/Integrate/Code_Examples/ruby.html +Redirect 301 /Code_Examples/Webhook_Examples/index.html https://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/index.html +Redirect 301 /Code_Examples/Webhook_Examples/go.html https://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/go.html +Redirect 301 /Code_Examples/Webhook_Examples/nodejs.html https://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/nodejs.html +Redirect 301 /Code_Examples/Webhook_Examples/php.html https://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/php.html +Redirect 301 /Code_Examples/Webhook_Examples/python.htmlhttps://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/python.html +Redirect 301 /Code_Examples/Webhook_Examples/csharp.html https://sendgrid.com/docs/Integrate/Code_Examples/Webhook_Examples/csharp.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/index.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/index.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/go.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/go.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/nodejs.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/nodejs.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/perl.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/perl.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/php.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/php.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/python.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/python.html +Redirect 301 /Code_Examples/SMTP_API_Header_Examples/ruby.html https://sendgrid.com/docs/Integrate/Code_Examples/SMTP_API_Header_Examples/ruby.html + +####### +# +# /docs/Delivery_Metrics - moved to User Guide - originally sendgrid.com/docs/Delivery_Metrics/ +# +####### +Redirect 301 /Delivery_Metrics/index.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/index.html +Redirect 301 /Delivery_Metrics/advanced_statistics.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/advanced_statistics.html +Redirect 301 /Delivery_Metrics/alerts.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/alerts.html +Redirect 301 /Delivery_Metrics/categories.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/categories.html +Redirect 301 /Delivery_Metrics/email_activity.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/email_activity.html +Redirect 301 /Delivery_Metrics/email_error_messages.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/email_error_messages.html +Redirect 301 /Delivery_Metrics/email_reports.html https://sendgrid.com/docs/User_Guide/Delivery_Metrics/email_reports.html + +####### +# +# /docs/Integrate +# +####### +Redirect 301 /Integrate/Mail_Clients/outlook_2010.html https://sendgrid.com/docs/Integrate/Mail_Clients/outlook_2013.html + +####### +# +# /docs/Marketing Email - moved to User Guide - originally sendgrid.com/docs/Marketing_Emails/ +# +####### +Redirect 301 /Marketing_Emails/Email_Marketing_Campaigns https://sendgrid.com/docs/Glossary/Email_Types +Redirect 301 /Marketing_Emails/ https://sendgrid.com/docs/User_Guide/Marketing_Emails/ +Redirect 301 /Marketing_Emails/analytics.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/create_manage.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/dashboard.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/tags.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/unsubscribes.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/recipients.html https://sendgrid.com/docs +Redirect 301 /Marketing_Emails/sender_address.html https://sendgrid.com/docs + +####### +# +# /docs/Transactional Email - moved to User Guide - originally sendgrid.com/docs/Transactional_Email +# +####### +Redirect 301 /Transactional_Email/index.html https://sendgrid.com/docs/User_Guide/Transactional_Email/index.html +Redirect 301 /Transactional_Email/unsubscribes.html https://sendgrid.com/docs/User_Guide/Transactional_Email/unsubscribes.html +Redirect 301 /Transactional_Email/Template_Engine/setup_guide.html https://sendgrid.com/docs/User_Guide/Transactional_Email/Template_Engine/setup_guide.html + +####### +# +# /docs/User Guide +# +####### +Redirect 301 /User_Guide/advanced_suppression_manager.html https://sendgrid.com/docs/User_Guide/Email_Deliverability/Subscription_Tracking/index.html +Redirect 301 /User_Guide/attachments.html https://sendgrid.com/docs/User_Guide/Email_Deliverability/attachments.html +Redirect 301 /User_Guide/managing_unsubscribes.html https://sendgrid.com/docs/User_Guide/Subscription_Tracking/index.html +Redirect 301 /User_Guide/multiple_credentials.html https://sendgrid.com/docs/User_Guide/Account_Settings/multiple_credentials.html +Redirect 301 /User_Guide/peer_invitations.html https://sendgrid.com/docs/Marketing_Emails/Email_Marketing_Campaigns/peer_invitations.html +Redirect 301 /User_Guide/reconfirmation.html https://sendgrid.com/docs/Marketing_Emails/Email_Marketing_Campaigns/reconfirmation.html +Redirect 301 /User_Guide/sending_practices.html https://sendgrid.com/docs/User_Guide/Account/account_changes.html +Redirect 301 /User_Guide/smtp_ports.html https://sendgrid.com/docs/User_Guide/Setting_Up_Your_Server/smtp_ports.html +Redirect 301 /User_Guide/template_engine_setup.html https://sendgrid.com/docs/Transactional_Email/Template_Engine/setup_guide.html +Redirect 301 /User_Guide/template_engine_setup.html https://sendgrid.com/docs/User_Guide/Transactional_Email/Template_Engine/setup_guide.html +Redirect 301 /User_Guide/warming_up.html https://sendgrid.com/docs/User_Guide/Setting_Up_Your_Server/warming_up.html +Redirect 301 /User_Guide/whitelabel_wizard.html https://sendgrid.com/docs/User_Guide/Setting_Up_Your_Server/whitelabel_wizard.html + +####### +# +# /docs/VidGrid +# +####### +Redirect 301 /VidGrid/Email_Activity/activity.html https://sendgrid.com/docs/VidGrid/email_activity.html +Redirect 301 /VidGrid/Marketing_Emails/Setup/overview.html https://sendgrid.com/docs/VidGrid/Marketing_Emails/marketing_emails_setup.html +Redirect 301 /VidGrid/Template_Engine/template_engine.html https://sendgrid.com/docs/VidGrid/template_engine.html +Redirect 301 /VidGrid/Whitelabel/whitelabel.html https://sendgrid.com/docs/VidGrid/whitelabel.html + + +