From 3f2ab7dd2971ee3625985467db7548aab3916a14 Mon Sep 17 00:00:00 2001 From: Dmytro Shevtsov Date: Fri, 15 Sep 2023 15:03:18 -0500 Subject: [PATCH] Add plugin to redirect 2.3 pages --- _plugins/page-params/redirect_23.rb | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 _plugins/page-params/redirect_23.rb diff --git a/_plugins/page-params/redirect_23.rb b/_plugins/page-params/redirect_23.rb new file mode 100644 index 00000000000..0905968dd14 --- /dev/null +++ b/_plugins/page-params/redirect_23.rb @@ -0,0 +1,42 @@ +# Copyright 2023 Adobe +# All Rights Reserved. +# +# NOTICE: All information contained herein is, and remains +# the property of Adobe and its suppliers, if any. The intellectual +# and technical concepts contained herein are proprietary to Adobe +# and its suppliers and are protected by all applicable intellectual +# property laws, including trade secret and copyright laws. +# Dissemination of this information or reproduction of this material +# is strictly forbidden + +# This plugin redirects 2.3 pages to the DevSite. +# It uses redirect metadata from the 2.4 version of the page. +# If there is no 2.4 version of the page, then it redirects to https://developer.adobe.com/commerce/docs/ + +Jekyll::Hooks.register :pages, :post_init do |page| + # Skip pages where the parameter is already set + next unless page.path.start_with? 'guides/v2.3/' + + # Process only files with 'md' and 'html' extensions + next unless File.extname(page.path).match?(/md|html/) + + # Skip redirects + next if page.name == 'redirect.html' + + # Skip pages where the parameter is already set + next if page.data['redirect_to'] + + pages = page.site.pages + + path_23 = page.path + + path_24 = path_23.sub('/v2.3/', '/v2.4/') + + page_24 = pages.find { |page| page.path == path_24 } + + if page_24.nil? + page.data['redirect_to'] = 'https://developer.adobe.com/commerce/docs/' + else + page.data['redirect_to'] = page_24.data['redirect_to'] + end +end