Middleman: run custom action after build

middleman, ruby

Solution

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.thor.source_paths << File.dirname(__FILE__)
  builder.thor.copy_file(src,dst)
end

Problem

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.

Original source