|
2 | 2 | config = site.config["post_process"] |
3 | 3 | next unless config |
4 | 4 |
|
| 5 | + cache = nil |
5 | 6 | terser = config["terser"] |
6 | 7 | if terser.is_a?(Hash) |
7 | 8 | terser.each do |terser_output, terser_inputs| |
8 | 9 | next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array) |
9 | 10 |
|
| 11 | + cache = Jekyll::Cache.new("PostProcess") unless cache |
10 | 12 | terser_codes = [] |
11 | 13 | terser_inputs_all_exist = true |
12 | 14 | terser_inputs.each do |file| |
|
21 | 23 |
|
22 | 24 | if terser_inputs_all_exist |
23 | 25 | destination = File.join(site.dest, terser_output.to_s) |
24 | | - File.write(destination, Script.call("terser", code: terser_codes.join(";"))) |
| 26 | + code = terser_codes.join(";") |
| 27 | + hash = Digest::SHA256.hexdigest(code) |
| 28 | + unless cache.key?("terser_#{hash}") |
| 29 | + cache["terser_#{hash}"] = Script.call("terser", code: code) |
| 30 | + end |
| 31 | + File.write(destination, cache["terser_#{hash}"]) |
25 | 32 | Jekyll.logger.info "Post Process:", "[terser] #{terser_output}" |
26 | 33 | end |
27 | 34 | end |
|
44 | 51 | Jekyll.logger.info "Post Process:", "[remove_dirs] #{dir}" |
45 | 52 | end |
46 | 53 | end |
| 54 | + |
| 55 | + # clean history jekyll cache |
| 56 | + jekyll_cache_dir = File.dirname(site.cache_dir) |
| 57 | + current_cache_name = File.basename(site.cache_dir) |
| 58 | + if File.basename(jekyll_cache_dir) == ".jekyll-cache" |
| 59 | + Dir.entries(jekyll_cache_dir).select do |entry| |
| 60 | + next if entry == "." || entry == ".." |
| 61 | + entry_path = File.join(jekyll_cache_dir, entry) |
| 62 | + if File.file?(entry_path) |
| 63 | + File.delete(entry_path) |
| 64 | + Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}" |
| 65 | + elsif File.directory?(entry_path) |
| 66 | + if entry < current_cache_name |
| 67 | + FileUtils.rm_rf(entry_path) |
| 68 | + Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}" |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
47 | 73 | end |
0 commit comments