Configuring Jekyll for Cloudflare Pages previews
Cloudflare Pages previews deployments at
<branch-or-commit>.<project>.pages.dev. Those previews are useful to review
content and layout and to test specific features (e.g., OpenGraph integration
and RSS feed/sitemap generation, which can be validated once online through
third party tools). For those features to work correctly, Jekyll needs to know
the url at which it is serving its assets.
Cloudflare builders expose the URL for previews through the CF_PAGES_URL
environmental variable. We can make Jekyll aware of it through this
build_cloudflare.sh script:
configs="_config.yml"
if [ -n "${CF_PAGES_URL:-}" ]; then
echo "url: $CF_PAGES_URL" > _cf_url.yml
configs="${configs},_cf_url.yml"
fi
bundle exec jekyll build --config "$configs"
To run it, set the script as the build command in your Cloudflare Workers and Pages configuration.