You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: rakelib/update.rake
+34
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,40 @@ namespace :update do
48
48
update_dirsubrepo['directory']
49
49
end
50
50
end
51
+
desc'Find and replace links from "tmp/migrated-from-to.csv" in files at the provided directory. Example: rake update:migrated_links dir=path/to/codebase'
52
+
task:migrated_linksdo
53
+
#
54
+
# check if 'tmp/migrated-from-to.csv' exists
55
+
links_file='tmp/migrated-from-to.csv'
56
+
abort'FAILED. Missing "tmp/migrated-from-to.csv" file. Make sure that your _config.local.yml file contains the "migrated_log: generate_file" parameter.'unlessFile.exist?links_file
57
+
# check if the provided directory ('dir') exist
58
+
dir=ENV['dir']
59
+
abort'FAILED. Missing argument "dir". Provide a directory to check the links. Example: rake update:migrated_links dir=path/to/codebase'unlessdir
60
+
abort"FAILED. Check the path provided through the 'dir' argument. The provide directory does not exist: #{dir}"unlessDir.exist?(dir)
61
+
# parse 'tmp/migrated-from-to.csv'
62
+
links=CSV.readlinks_file
63
+
# for each file in dir, find and replace all links
64
+
Dir[File.join(dir,'**','*')].eachdo |file|
65
+
# ignore directory paths
66
+
nextifFile.directory?file
67
+
# ignore symlinks
68
+
nextifFile.symlink?file
69
+
# ignore empty files
70
+
nextifFile.zero?file
71
+
# ignore binary files
72
+
nextifRDoc::Parser.binary?file
73
+
74
+
# read the file
75
+
content=File.readfile
76
+
# iterate through the array of links
77
+
links.eachdo |redirect|
78
+
# replace first link from the array with the second links
0 commit comments