|
| 1 | +# Copyright 2023 Adobe |
| 2 | +# All Rights Reserved. |
| 3 | +# |
| 4 | +# NOTICE: All information contained herein is, and remains |
| 5 | +# the property of Adobe and its suppliers, if any. The intellectual |
| 6 | +# and technical concepts contained herein are proprietary to Adobe |
| 7 | +# and its suppliers and are protected by all applicable intellectual |
| 8 | +# property laws, including trade secret and copyright laws. |
| 9 | +# Dissemination of this information or reproduction of this material |
| 10 | +# is strictly forbidden |
| 11 | + |
| 12 | +# This plugin redirects 2.3 pages to the DevSite. |
| 13 | +# It uses redirect metadata from the 2.4 version of the page. |
| 14 | +# If there is no 2.4 version of the page, then it redirects to https://developer.adobe.com/commerce/docs/ |
| 15 | + |
| 16 | +# frozen_string_literal: true |
| 17 | + |
| 18 | +Jekyll::Hooks.register :pages, :post_init do |page| |
| 19 | + # Skip pages where the parameter is already set |
| 20 | + next unless page.path.start_with? 'guides/v2.3/' |
| 21 | + |
| 22 | + # Process only files with 'md' and 'html' extensions |
| 23 | + next unless File.extname(page.path).match?(/md|html/) |
| 24 | + |
| 25 | + # Skip redirects |
| 26 | + next if page.name == 'redirect.html' |
| 27 | + |
| 28 | + # Skip pages where the parameter is already set |
| 29 | + next if page.data['redirect_to'] |
| 30 | + |
| 31 | + pages = page.site.pages |
| 32 | + |
| 33 | + path_23 = page.path |
| 34 | + |
| 35 | + path_24 = path_23.sub('/v2.3/', '/v2.4/') |
| 36 | + |
| 37 | + page_24 = pages.find { |page| page.path == path_24 } |
| 38 | + |
| 39 | + if page_24.nil? |
| 40 | + page.data['redirect_to'] = 'https://developer.adobe.com/commerce/docs/' |
| 41 | + else |
| 42 | + page.data['redirect_to'] = page_24.data['redirect_to'] |
| 43 | + end |
| 44 | +end |
0 commit comments