在 Jekyll Hook 中访问 _config.yml 中定义的变量

Access variables defined in _config.yml within Jekyll Hook

如何从 Jekyll::Hooks 插件中访问站点变量(即 _config.yml 中定义的变量)?

我原以为 site.variable 会这样做,但这引发了:

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

啊哈,必须将站点变量传递给挂钩本身:

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