Include json file from one level up outside SOURCE dir

Can I somehow make Jekyll include my file.json which sits in the parent directory of my Jekyll source directory?

+ docs
  + _site
  - _config.yml
- file.json

It should end up in the root of the created site:

+ docs
  + _site
    - file.json
  - _config.yml
- file.json

Thanks!

Since file.json is outside site.source, it won’t be seen by Jekyll under normal circumstances. The only way out would be write a plugin to include that file at runtime. Paste the following into a file at path docs/_plugins/external_json.rb:

module ExternalJSON
  class Generator < Jekyll::Generator
    def generate(site)
      site.static_files << Jekyll::StaticFile.new(site, site.source, "../", "file.json")
    end
  end
end

The next time you build your site, the _site/file.json will be generated.

Disclaimer: The above code is untested and may or may not work locally but will definitely not work on GitHub Pages or if you build with --safe switch.

Thanks for your quick answer. Maybe I should have included that I thought using the INCLUDE config setting the file could be included (include: ['../file.json'])? I ran jekyll with verbose output but it did not report the file as missing but also did not include it when outputting _site.

Cause I am using gh-pages for this site, I’d really not depend on plugins (that are not supported by github).

Is there no other way?

GitHub Pages is very restrictive for security reasons. That’s the reason they do not allow third-party plugins. For the same reason, there is absolutely no straight-forward way to achieve what you’re looking for when serving via GitHub Pages.

The only way is build your site locally and upload the contents of _site to GitHub (usually to a gh-pages branch so that the raw source-code can continue residing on the master branch.)