NARKOZ NARKOZ - 2 months ago 22
Ruby Question

Middleman: run custom action after build

How can I run custom action (eg. copy file to build folder) after middleman built pages?

I want to put

Readme.md
file from source to build dir.

Answer

You can use after_build hook. add following code to config.rb.

The hook which you can use is written in https://middlemanapp.com/advanced/custom_extensions/ .

Although it is not well documented, it seems that after_build can use directly in config.rb, without writing your own extension.

after_build do |builder|
  src = File.join(config[:source],"Readme.md")
  dst = File.join(config[:build_dir],"Readme.md")
  builder.source_paths << File.dirname(__FILE__)
  builder.copy_file(src,dst)
end