ivantsepp / jekyll-git_metadata

Expose Git metadata to Jekyll.
MIT License
67 stars 25 forks source link

Not working when building using Jekyll Ruby interface with Rake #26

Closed erikw closed 3 years ago

erikw commented 3 years ago

Hey,

first thanks for making this nice plugin. I'm looking forward to #25!

I noticed as I migrated my website's build process to rake that this plugin does not work when building with Jekyll command ruby interface. It does work perfectly when building with the Jekyll shell command like $bundle exec jekyll build.

I built a minimal website showing off this problem here erikw/jekyll-3.x.x-test/ (linked branch: jekyll-git_metadata)

The relevant snippet from the Rakefile would be:

task :build do
  puts "Building site...".bold
  Jekyll::Commands::Build.process(verbose: true)
  #sh 'jekyll build'
end

There are no build errors but silently there is no output for the variables the plugin provide e.g. {{ site.git.last_commit.short_sha }} will just render to an empty string. See the index.md. There is also no .git-metadata/ directory generated.

Note that if swapping the Jekyll::Commands::Build.proces() for the line under sh 'jekyll build' it all works perfectly and the git last commit short SHA is shown in the generated index.html.

What could the problem be here? Everything else works perfectly when using the ruby build interface for Jekyll, it's just this plugin that's troublesome for me, as shown in the minimal example repo I created.

Versions used can be seen in the example Gemfile /Gemfile.lock.

erikw commented 3 years ago

Well since I made a minimal example, it was very easy for me to take a close look and I found the issue very quickly!

I simply needed to add in _config.yml:

plugins:
  - jekyll-git_metadata

and then it works!

I was assuming that this was not necessary as it says at https://jekyllrb.com/docs/plugins/installation/#the-jekyll_plugins-group about the Gemfile :jekyll_plugins group:

Jekyll gives this particular group of gems in your Gemfile a different treatment. Any gem included in this group is loaded before Jekyll starts processing the rest of your source directory.

A gem included here will be activated even if its not explicitly listed under the plugins: key in your site’s config file.

Because of this, I never use the plugins key in the Jekyll _config.yml and just use the :jekyll_plugins group in the Gemfile, as seen in the minimal repo as well: Gemfile#L15-L18.

This works for all Jekyll plugins that I use, but not this one apparently as demonstrated in the minimal example I setup.

For me there is not a workaround. I'm not sure if I should leave this issue open though. If i understand the official Jekyll documentation correctly, the plugin should work still if only added to the build group but not set in the Jekyll configuration file. What do yo say @ivantsepp ?

erikw commented 3 years ago

I discovered now that there are more plugins that silently fail too when building in this way. My bad! I'll close this issue