Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
erikw opened this issue Jul 12, 2021 · 2 comments
Closed

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

erikw opened this issue Jul 12, 2021 · 2 comments

Comments

@erikw
Copy link

erikw commented Jul 12, 2021

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 erikw changed the title Not working when building with Jekyll Ruby interface from rake Not working when building using Jekyll Ruby interface with Rake Jul 12, 2021
@erikw
Copy link
Author

erikw commented Jul 12, 2021

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
Copy link
Author

erikw commented Jul 13, 2021

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

@erikw erikw closed this as completed Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant