Skip to content

Commit dee6314

Browse files
welpokodster28
andauthored
add dynamic base URL config for Zola preview deployments (#21999)
* add dynamic base URL config for Zola preview deployments * use config.toml base_url * Update src/content/docs/pages/framework-guides/deploy-a-zola-site.mdx --------- Co-authored-by: Kody Jackson <[email protected]>
1 parent 1fb90cc commit dee6314

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/content/docs/pages/framework-guides/deploy-a-zola-site.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ base_url = "https://my-zola-project.pages.dev"
110110

111111
Every time you commit new code to your Zola site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to [preview deployments](/pages/configuration/preview-deployments/) on new pull requests, so you can preview how changes look to your site before deploying them to production.
112112

113+
### Handling Preview Deployments
114+
115+
When working with Cloudflare Pages, you might use preview deployments for testing changes before merging to your main branch. However, these preview deployments use different URLs (like `https://your-branch-name.my-zola-project.pages.dev`), which can cause issues with asset loading if your `base_url` is hardcoded.
116+
117+
To fix this, modify your build command in the Cloudflare Pages configuration to dynamically set the base URL depending on the environment:
118+
119+
```sh
120+
if [ "$CF_PAGES_BRANCH" = "main" ]; then zola build; else zola build --base-url $CF_PAGES_URL; fi
121+
```
122+
123+
This command uses:
124+
- The `base_url` set in `config.toml` when building from the `main` branch
125+
- The preview deployment URL (automatically provided by Cloudflare Pages as `$CF_PAGES_URL`) for all other branches
126+
113127
<Render file="framework-guides/learn-more" params={{ one: "Zola" }} />

0 commit comments

Comments
 (0)