utils/posts_fix.rb
def move_files(nodes, fixed_content, new_post_dir, original_file)
  nodes.each do |node|
    source = node.value.gsub("http://www.justinball.com", "")
    if !source.start_with?("http") && !source.include?("mailto:")
      # strip since some of the posts have whitespace in their links
      fixed_content.gsub!(source, File.basename(source).strip)
      # Move each file to post directory
      file_path = File.join("./static", source.strip)

      # From way back in the wp days. There are still posts that have these links:
      file_path.gsub!("wp-content/uploads", "images/posts")
      file_path.gsub!("Identica.png/", "Identica.png")

      # We only care about links to files and we're making the assumption that files
      # have an extension while other links won't have a file extension.
      if !File.extname(file_path).empty?
        if File.exists? file_path
          FileUtils.mv(file_path, new_post_dir)
        else
          puts "#{original_file} -- Source file not found #{file_path}"
        end
      end
    end
  end
end
# Note that the function changes the value of fixed_content
Note that the function changes the value of fixed_content
Note that the function changes the value of fixed_content
def move_files(nodes, fixed_content, new_post_dir, original_file)
  nodes.each do |node|
    source = node.value.gsub("http://www.justinball.com", "")
    if !source.start_with?("http") && !source.include?("mailto:")
      fixed_content.gsub!(source, File.basename(source).strip)
      file_path = File.join("./static", source.strip)
      file_path.gsub!("wp-content/uploads", "images/posts")
      file_path.gsub!("Identica.png/", "Identica.png")
      if !File.extname(file_path).empty?
        if File.exists? file_path
          FileUtils.mv(file_path, new_post_dir)
        else
          puts "#{original_file} -- Source file not found #{file_path}"
        end
      end
    end
  end
end
def move_files ( nodes , fixed_content , new_post_dir , original_file ) nodes . each do | node | source = node . value . gsub ( "http://www.justinball.com" , "" ) if ! source . start_with? ( "http" ) && ! source . include? ( "mailto:" ) fixed_content . gsub! ( source , File . basename ( source ) . strip ) file_path = File . join ( "./static" , source . strip ) file_path . gsub! ( "wp-content/uploads" , "images/posts" ) file_path . gsub! ( "Identica.png/" , "Identica.png" ) if ! File . extname ( file_path ) . empty? if File . exists? file_path FileUtils . mv ( file_path , new_post_dir ) else puts "#{original_file} -- Source file not found #{file_path}" end end end end end
Note that the function changes the value of fixed_content
Note that the function changes the value of fixed_content
# strip since some of the posts have whitespace in their links # Move each file to post directory # From way back in the wp days. There are still posts that have these links: # We only care about links to files and we're making the assumption that files # have an extension while other links won't have a file extension.
nodes
fixed_content
new_post_dir
original_file