Hugo
To deploy your site to Pages:
- Log in to the Cloudflare dashboard and select your account.
- In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.
- Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:
Configuration option Value Production branch mainBuild command hugoBuild directory publicHugo allows you to configure thebaseURLof your application. This allows you to utilize theabsURLhelper to construct full canonical URLs. In order to do this with Pages, you must provide the-bor--baseURLflags with theCF_PAGES_URLenvironment variable to yourhugobuild command.
Your final build command may look like this:
$ hugo -b $CF_PAGES_URL
After completing configuration, click the Save and Deploy button. You should see Cloudflare Pages installing hugo and your project dependencies, and building your site, before deploying it.
After deploying your site, you will receive a unique subdomain for your project on *.pages.dev.
Every time you commit new code to your Hugo site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.
Based on cloudflare Docs from May 2023
To use a specific version of Hugo, create the HUGO_VERSION environment variable in your Pages project > Settings > Environment variables. Set the value as the Hugo version you want to specify.
For example, HUGO_VERSION: 0.110.0.
If you plan to use preview deployments, make sure you also add environment variables to your Preview environment.
Create a file with the name _headers in the folder /static
/*
Content-Security-Policy: default-src 'self';
X-Frame-Options: SAMEORIGIN
Permissions-Policy: autoplay=(*), fullscreen=(*), geolocation=*
X-XSS-Protection: 1; mode=block
# Implemented directly from cloudflare:
# Strict-Transport-Security: max-age=31536000; includeSubDomains
# Implemented directly from cloudflare:
# X-Content-Type-Options: nosniff
# Implemented directly from cloudflare:
# Referrer-Policy: same-origin
# Unclear configuration
# Permissions-Policy: autoplay=(*), fullscreen=(*), geolocation=*