Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add plugin to redirect 2.3 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Sep 15, 2023
1 parent 96930d7 commit 3f2ab7d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions _plugins/page-params/redirect_23.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f2ab7d

Please sign in to comment.