Middleland: start custom actions after build

How to start a custom action (for example, copy a file to a folder with a folder) after the pages created by the broker?

I want to put the Readme.md file from the source to create the dir.

+6
source share
2 answers

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

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

Although this is poorly documented, it seems that after_build can use directly in config.rb without writing its 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 
+10
source

Although the after_build tip is the default answer, I would suggest using a task runner to complete the task.

A task runner is cool to simplify such procedures. For example, most Middleman projects require deployment to a hosting server. Therefore, if you need a runner for deployment, you can use it to copy a file.

If you are not using a task runner, consider using this. This will save you a lot of trouble.

Rake is the natural choice for Middleman Ruby, but I prefer Grunt .

Here's the Grunt copy job (uses the grunt-contrib-copy plugin):

 copy: { bowercomponents: { files: [ { expand: true, flatten: true, src: [ 'source/Readme.md' ], dest: 'build/', filter: 'isFile' } ] } } 

And here is the deployment task using the grunt-shell plugin:

 shell: { buildAndPublish: { command: [ 'echo "### Building ###"', 'bundle exec middleman build --verbose', 'echo "### Adding built files to git index ###"', 'cd build/', 'git add -A', 'echo "### Commiting changes ###"', 'git commit -m build', 'echo "### Pushing the commit to the gh-pages remote branch ###"', 'git push origin gh-pages', 'cd ..' ].join(' && '), options: { stdout: true, stderr: true } } } 
+1
source

Source: https://habr.com/ru/post/969880/


All Articles