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

Commit 3f2ab7d

Browse files
committed
Add plugin to redirect 2.3 pages
1 parent 96930d7 commit 3f2ab7d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

_plugins/page-params/redirect_23.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
Jekyll::Hooks.register :pages, :post_init do |page|
17+
# Skip pages where the parameter is already set
18+
next unless page.path.start_with? 'guides/v2.3/'
19+
20+
# Process only files with 'md' and 'html' extensions
21+
next unless File.extname(page.path).match?(/md|html/)
22+
23+
# Skip redirects
24+
next if page.name == 'redirect.html'
25+
26+
# Skip pages where the parameter is already set
27+
next if page.data['redirect_to']
28+
29+
pages = page.site.pages
30+
31+
path_23 = page.path
32+
33+
path_24 = path_23.sub('/v2.3/', '/v2.4/')
34+
35+
page_24 = pages.find { |page| page.path == path_24 }
36+
37+
if page_24.nil?
38+
page.data['redirect_to'] = 'https://developer.adobe.com/commerce/docs/'
39+
else
40+
page.data['redirect_to'] = page_24.data['redirect_to']
41+
end
42+
end

0 commit comments

Comments
 (0)