Search code examples
jekyll

Access variables defined in _config.yml within Jekyll Hook


How can one access site variables (i.e. variables defined in _config.yml) from within a Jekyll::Hooks plugin?

I thought site.variable would do it but this raises:

Error:  undefined local variable or method `site' for main:Object

Solution

  • Aha, one has to pass the site variable into the hook itself:

    Jekyll::Hooks.register :site, :post_write do |site|
      if site.config['create_index']
        system('npm run index')
      end
    end