I am managing the url difference between local dev and netlify by loading two _config.yml files, with the first specifying url: ‘https://angry-tereshkova-959566.netlify.com’, and the second overwrites that with url: ‘http://localhost:4000’. This doesn’t work for a preview because I cannot predict the url.
With the hugo example, it allows the passing of that setting via the command build command and Netlify provides an environment variable which can be used in our build environment.
I don’t know if there is a way to do this with jekyll or not. One workaround would be to modify the jekyll config file and insert this environment variable ($DEPLOY_PRIME_URL) into that YAML file during the build.
This might be done using a two part build command:
a script that programmatically inserts the $DEPLOY_PRIME_URL value into the YAML file
the actually build command
For example:
script-that-inserts.sh && jekyll build
Another solution is to modify the theme to use absolute URLs for other assets.
So arg, I’ve been googling and asking, and for some reason a lot of people want to have access to env vars in jekyll but no one seems to be succeeding.
It seems like if I can run a line in CLI that creates a temp _conf_build.yml file I can load it and overwrite site.url. I’ll try to learn about that now. As a newbie, I have been able to use netlify with almost zero learning; I just made a local jekyll site, pushed it to a repo, and bam! netlify built and served it for me. So nice.
Uses ‘url’ rather than ‘site’.
DEPLOY_PRIME_URL is the ‘pretty’ url, DEPLOY_URL works too, but is not the same as the review app one. - Build environment variables | Netlify Docs