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

Commit 6d8934b

Browse files
committed
Add a config parameter to enable the file gen
1 parent 0ae83fc commit 6d8934b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

_plugins/generators/migrated_log.rb

+15-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# - site.data.migration.remained_migrating_pages
1212
#
1313
# And generates the `tmp/migrated-from-to.csv` file with the list of links "from" and "to" for the migrated pages.
14-
#
14+
# To enable the file generation, add 'migrated_log: generate_file' to _config.local.yml.
15+
#
1516

1617
module Jekyll
1718
# Custom generator for MRG pages
@@ -29,10 +30,12 @@ def generate(site)
2930
remained_migrating_pages = all_migrating_pages - migrated_pages
3031
migrated_pages_data = []
3132

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"))
33+
if (site.config['migrated_log']&.include? 'generate_file')
34+
# Create a CSV file that contains links 'from' and 'to' for migrated pages
35+
migrated_pages = pages.select { |pages| pages.data['status']&.include? 'migrated' }
36+
redirects = migrated_pages.map { |page| "https://devdocs.magento.com#{page.data['redirect']['from']},#{page.data['redirect']['to']}" }
37+
File.write('tmp/migrated-from-to.csv', redirects.join("\n"))
38+
end
3639

3740
# Create an array of JSON objects that contain metadata for migrated pages
3841
migrated_pages.each do |page|
@@ -48,12 +51,12 @@ def generate(site)
4851
migrated_from: site.baseurl + page.url,
4952
redirected_to: page.data['redirect_to'] || abort("Error in '#{page.path}'.\n Check 'redirect_to' in the file's frontmatter.".red),
5053
redirected_to_source: if page.data['redirect_to'].start_with?('https://experienceleague.adobe.com')
51-
'Adobe Experience League'
52-
elsif page.data['redirect_to'].start_with?('https://developer.adobe.com')
53-
'Adobe Developer'
54-
else
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
56-
end
54+
'Adobe Experience League'
55+
elsif page.data['redirect_to'].start_with?('https://developer.adobe.com')
56+
'Adobe Developer'
57+
else
58+
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
59+
end
5760
}
5861
migrated_pages_data << migrated_page
5962
end
@@ -110,7 +113,7 @@ def generate(site)
110113
'all_migrating_pages' => all_migrating_pages.map(&:path),
111114
'remained_migrating_pages' => remained_migrating_pages.map(&:path)
112115
}
113-
116+
114117
migrated_pages_data
115118
end
116119
end

0 commit comments

Comments
 (0)