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

Commit 28ee148

Browse files
committed
Update migrated_log.rb
Use 'status: migrated' to select migrated pages Write migrated redirects to 'tmp/migrated-from-to.csv'
1 parent 8465701 commit 28ee148

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

_plugins/generators/migrated_log.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
# See COPYING.txt for license details.
55

66
# This plugin generates the page that contains a list of migrated topics: https://devdocs.magento.com/migrated.html
7-
# Also, it adds global data:
7+
# It adds global data:
88
# - site.data.migration.migrated_pages
99
# - site.data.migration.deprecated_pages
1010
# - site.data.migration.all_migrating_pages
1111
# - site.data.migration.remained_migrating_pages
1212
#
13+
# And generates the `tmp/migrated-from-to.csv` file with the list of links "from" and "to" for the migrated pages.
14+
#
1315

1416
module Jekyll
1517
# Custom generator for MRG pages
@@ -19,14 +21,19 @@ class MigratedLog < Generator
1921
def generate(site)
2022
@site = site
2123
pages = @site.pages
22-
migrated_pages = pages.select { |page| page.data['layout']&.include? 'migrated' }
24+
migrated_pages = pages.select { |page| page.data['status']&.include? 'migrated' }
2325
v2_3_pages = pages.select { |page| page.data['guide_version'] == '2.3' }
2426
remained_pages = pages - v2_3_pages
2527
deprecated_pages = remained_pages.select { |page| page.data['group'].nil? || page.data['redirect_to'] }
2628
all_migrating_pages = remained_pages - deprecated_pages
2729
remained_migrating_pages = all_migrating_pages - migrated_pages
2830
migrated_pages_data = []
2931

32+
# Create a CSV file that contains links 'from' and 'to' for migrated pages
33+
migrated_pages = pages.select {|pages| pages.data['status']&.include? 'migrated' }
34+
redirects = migrated_pages.map {|page| "https://devdocs.magento.com#{page.data['redirect']['from']},#{page.data['redirect']['to']}"}
35+
File.write('tmp/migrated-from-to.csv', redirects.join("\n"))
36+
3037
# Create an array of JSON objects that contain metadata for migrated pages
3138
migrated_pages.each do |page|
3239
migrated_page = {
@@ -39,13 +46,13 @@ def generate(site)
3946
'label') || abort("Error in '#{page.path}'.\n Check 'group' in the file's frontmatter or 'label' in the corresponding TOC.".red)
4047
end,
4148
migrated_from: site.baseurl + page.url,
42-
migrated_to: page.data['migrated_to'] || abort("Error in '#{page.path}'.\n Check 'migrated_to' in the file's frontmatter.".red),
43-
migrated_to_source: if page.data['migrated_to'].start_with?('https://experienceleague.adobe.com')
49+
redirected_to: page.data['redirect_to'] || abort("Error in '#{page.path}'.\n Check 'redirect_to' in the file's frontmatter.".red),
50+
redirected_to_source: if page.data['redirect_to'].start_with?('https://experienceleague.adobe.com')
4451
'Adobe Experience League'
45-
elsif page.data['migrated_to'].start_with?('https://developer.adobe.com')
52+
elsif page.data['redirect_to'].start_with?('https://developer.adobe.com')
4653
'Adobe Developer'
4754
else
48-
abort "Error in '#{page.path}'.\nThe 'migrated_to' parameter in the front matter points to the wrong domain: #{page.data['migrated_to']}.\nShould be 'https://experienceleague.adobe.com' or 'https://developer.adobe.com'".red
55+
abort "Error in '#{page.path}'.\nThe 'redirected_to' parameter in the front matter points to the wrong domain: #{page.data['redirect_to']}.\nShould be 'https://experienceleague.adobe.com' or 'https://developer.adobe.com'".red
4956
end
5057
}
5158
migrated_pages_data << migrated_page
@@ -59,7 +66,7 @@ def generate(site)
5966
content += "\n## #{guide}\n\n\n"
6067
topics.sort_by { |topic| topic[:title] }
6168
.each do |topic|
62-
content += "1. [#{topic[:title]}](#{topic[:migrated_from]}) has moved to [#{topic[:migrated_to_source]}](#{topic[:migrated_to]})\n"
69+
content += "1. [#{topic[:title]}](#{topic[:migrated_from]}) has moved to [#{topic[:redirected_to_source]}](#{topic[:redirected_to]})\n"
6370
end
6471
end
6572

@@ -103,7 +110,7 @@ def generate(site)
103110
'all_migrating_pages' => all_migrating_pages.map(&:path),
104111
'remained_migrating_pages' => remained_migrating_pages.map(&:path)
105112
}
106-
113+
107114
migrated_pages_data
108115
end
109116
end

0 commit comments

Comments
 (0)