Jekyll plugin gem

Hello, have a quick question. I am attempting to export a Jekyll plugin as a gem (it works fine when in the _plugins directory within the project).

However, after bulding and pushing the gem to rubygems.org and including the gem in the other Jekyll project. The following error is outputted:

Dependency Error: Yikes! It looks like you don't have jekyll-categorize-pages or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- jekyll-categorize-pages' If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/!

How do you debug/resolve this issue? I even mimicked a popular jekyll plugin gem (https://github.com/envygeeks/jekyll-assets) to make sure I have the proper structure and not missing anything. However, this same error is outputted. Is there a way to scaffold a jekyll plugin similar to theme (jekyll new plugin?) or is there a guide to creating a plugin as a gem and including it in Jekyll projects.

Are you using a Gemfile? If not I’d suggest doing so and adding it there so it’s marked as a dependency.

source 'https://rubygems.org'

gem 'jekyll'

group :jekyll_plugins do
  gem 'jekyll-categorize-pages'
end

Then prepend Jekyll commands with bundle exec e.g. bundle exec jekyll serve

Yes using a Gemfile. I also have the plugin gem within the group block just as you mentioned above. I am running the project using bundle exec jekyll serve also.

When I include it in the Gemfile and run bundle exec jekyll serve it serves the project correctly. However, if I add the jekyll-categorize-pages within the plugins list in the _config.yml, it outputs that error mentioned above.

If you’re adding it to the plugins: array in _config.yml then maybe you have to move it out of the plugin group in the Gemfile.

I haven’t built my own plugin so plugin devs can probably let you know. But I believe there’s some logic to “autoload” it when declaring it under group :jekyll_plugins. That’s likely where the error is coming from.

I went ahead and installed jekyll-categorize-pages from rubygems.org, and came up with the same error regardless of configuration. On looking into it further, there seems to be something wrong with the gem, as best I can tell. When I look in the gems folder it installs to, the folder is empty. When I manually download the gem and unpack it,

gem fetch jekyll-categorize-pages
gem unpack jekyll-categorize-pages

I also get an empty directory.

I also was getting an empty directory when installing the gem before. Now, I am getting the lib directory of the gem project when inspecting the gem directory after running gem install jekyll-categorize-pages. I am not sure what else is missing, I created a Github repo for the plugin here (https://github.com/bsubedi26/jekyll-categorize-pages) if you can spot any issues. Appreciate the help.

Just got a chance to take another look at this. Though there are other options, probably the easiest thing to do is to rename your lib/generator.rb file to match the name of the gem, i.e. lib/jekyll-categorize-pages.rb.

HTH

Thanks! That fixed the problem. Basically changed the file name from lib/generator.rb to lib/jekyll-categorize-pages.rb.