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

Commit c0e595d

Browse files
committed
Use site post_read hook
1 parent 00f74da commit c0e595d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

_plugins/page-params/redirect_23.rb

+20-17
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,33 @@
1515

1616
# frozen_string_literal: true
1717

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/'
18+
Jekyll::Hooks.register :site, :post_read do |site|
19+
pages = site.pages
2120

22-
# Process only files with 'md' and 'html' extensions
23-
next unless File.extname(page.path).match?(/md|html/)
21+
pages.each do |page|
22+
# Skip pages where the parameter is already set
23+
next unless page.path.start_with? 'guides/v2.3/'
2424

25-
# Skip redirects
26-
next if page.name == 'redirect.html'
25+
# Process only files with 'md' and 'html' extensions
26+
next unless File.extname(page.path).match?(/md|html/)
2727

28-
# Skip pages where the parameter is already set
29-
next if page.data['redirect_to']
28+
# Skip redirects
29+
next if page.name == 'redirect.html'
3030

31-
pages = page.site.pages
31+
# Skip pages where the parameter is already set
32+
next if page.data['redirect_to']
3233

33-
path_23 = page.path
34+
path_23 = page.path
3435

35-
path_24 = path_23.sub('/v2.3/', '/v2.4/')
36+
path_24 = path_23.sub('v2.3', 'v2.4')
37+
puts 'path_24: ' + path_24
3638

37-
page_24 = pages.find { |page| page.path == path_24 }
39+
page_24 = pages.find { |page| page.path == path_24 }
3840

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']
41+
if page_24.nil?
42+
page.data['redirect_to'] = 'https://developer.adobe.com/commerce/docs/'
43+
else
44+
page.data['redirect_to'] = page_24.data['redirect_to']
45+
end
4346
end
4447
end

0 commit comments

Comments
 (0)