Skip to content

Instantly share code, notes, and snippets.

@Uysim
Created May 21, 2017 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uysim/e5dce343a39c62ad0da0255a69003f83 to your computer and use it in GitHub Desktop.
Save Uysim/e5dce343a39c62ad0da0255a69003f83 to your computer and use it in GitHub Desktop.
This gist is rake for rails copy digest to nondigest assets
namespace :nondigest do
desc "TODO"
task precompile: :environment do
fingerprint = /\-[0-9a-f]{64}\./
filemap = {}
Dir["public/assets/**/*"].each do |file|
next if file !~ fingerprint
next if File.directory?(file)
nondigest = file.sub fingerprint, '.'
if filemap[nondigest]
if File.mtime(file) > filemap[nondigest][:time]
filemap[nondigest] = {file: file, time: File.mtime(file)}
end
else
filemap[nondigest] = {file: file, time: File.mtime(file)}
end
end
filemap.each do |nondigest, v|
File.delete(nondigest) if File.exist?(nondigest)
FileUtils.cp v[:file], nondigest, verbose: true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment