https://reverent-volhard-34212c.netlify.app/ is built on Jekyll.
I have set a Netlify environment variable with an Airtable API key.
I’ve installed the jekyll-dotenv gem so I can access the Netlify environment variable. This works when I use Liquid in layouts and includes (i.e. with {{ site.env.NETLIFY_ENV_VARIABLE_NAME }}).
However, I want to be able to access the variable in my site’s _config.yml file. I can’t do this as this is where I set my site variables, and Liquid won’t work here.
So my questions are:
Is there a way to access Netlify environment variables in Jekyll’s _config.yml file?
Is there a different approach to hiding API keys in Jekyll when the site is deployed from Github? (I don’t want to use a private repo.)
The only option for you would be to use Jekyll to build that _config.yml file for you. But this is going to be a circular reference, as Jekyll will probably need that file to build the site and that file would need to be dynamically built by Jekyll.
In that case, you’d have to resort to some other build tool (like a Node.js script), to generate the file during the build time before running Jekyll build.