Performing a build action after generation (is there a better way?) #1145

Closed
robmadole opened this Issue May 24, 2013 · 6 comments

Comments

Projects
None yet
5 participants

Hey Jekyll folks.

We're trying to integrate a build process that compiles less files into CSS.

https://github.com/FortAwesome/Font-Awesome/blob/3.2.0-wip/build/_plugins/site.rb#L83

What we came up with is to add a step into the Jekyll::Site class.

  class Site

    def process
      self.reset
      self.read
      self.generate
      self.render
      self.cleanup
      self.write

      self.build
    end

    ##
    # Special build process, the Makefile uses `lessc <file.less> <output.css>`
    def build
      system("make build", :chdir => self.config['destination'], :out => :err)
    end

  end

We use Jekyll to generate the Less files themselves (looping through a list of icons). Because of this we have to wait until after the write method is called.

What we have works, but it would be great to have a more "blessed" approach to this. I was going to write a plugin to do it but couldn't figure out how to wait until after the files were written.

Is there a better way?

For example, if I could write a plugin and do this it would fill me with joy:

def build()
    # Do build stuff here
end

Jekyll::Site.after_generation(build)

robmadole closed this May 24, 2013

Whoops click happy

robmadole reopened this May 24, 2013

Owner

parkr commented May 24, 2013

Heyo! This is a splendid idea. The extra code would behave as normal plugins and not be executed on GitHub Pages, but there is no reason we should force anyone to monkey-patch Site#process to implement a build feature.

I'd love to get the thoughts of the venerable @mattr-, @benbalter, and @dhcole.

Owner

mattr- commented May 25, 2013

I'm cool with this. I was just reading about hook methods in Sandi Metz's POODR book and was thinking something like this would be useful

Owner

parkr commented Jun 4, 2013

How would you envision it? Should plugins have access directly or should plugin authors have to monkey-patch a method intentionally left blank? It would cool if plugins could just hand us procs or something:

Jekyll.after_build do
  system("make build")
end

We should also come up with a way for plugins in a gemfile to be picked up rather than requiring that something be placed in plugins/.

Contributor

holic commented Jul 30, 2013

👍 for something like Jekyll.after_build

Owner

parkr commented Jul 31, 2014

Jekyll 3.0 is entirely hook-based, so this will work once that's finished.

parkr closed this Jul 31, 2014

jekyllbot locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.