Use the _config.yml file in the gem-based themes

Hello everyone.

I use Jekyll with the following environment on my computer:

  • ubuntu (last updated) SO used for development
  • jekyll
  • git

I’ve tested that I can use a “gem-based” theme locally in the Jekyll site directory with the following steps:

  1. upload the theme folder in the Jekyll site directory (root).
  2. In the gemfile (located in the Jekyll site directory): I add the following code gem "my_theme_name", :path => "".
  3. I run the bundle install command to “install” the theme.
  4. In the file _config.yml (in the Jekyll site directory) I add the following code: theme: my_theme_name.
  5. I run the jekyll serve command to use the website locally.

Everything is done correctly.

Now, depending on the configuration above, can I add the _config.yml file to the theme folder to handle theme configurations such as the Front Matter Default (https://jekyllrb.com/docs/configuration/#front-matter-defaults) ?

I’ve tried adding the _config.yml file to the theme folder, but it is ignored.
Only the _config.yml file in the root is considered.

Best regards.
Ivan

You can’t currently “bundle” in a config file or _data files with a theme-gem. Those files and directories are ignored regardless if they are in the gem or not (only _layouts, _includes, _sass, and assets come along for the ride).

What you can do is use the jekyll-data plugin and add it as a dependency to your theme gem. It will then pull in the _config.yml in the theme-gem.

1 Like

There’s a pull request on one of my theme-gems if you want to see how to add jekyll-data as a dependency to your theme’s gemspec.

1 Like

@mmistakes many thanks for the prompt reply.

I will try this plugin, which I had already seen but never used.

I think using a specific file (like _config.yml) to configure a theme is a great way to make an independent Gem-based theme.