# Distinguish between release and test versions

**URL:** <https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398>\
**Category:** Feature requests\
**Created:** [April 29, 2020, 1:39pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398 "2020-04-29T13:39:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![TeFiLeDo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tefiledo/32/631_2.png) [@TeFiLeDo](https://zola.discourse.group/u/TeFiLeDo)\
**Post date:** [April 29, 2020, 1:39pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/1 "2020-04-29T13:39:57Z")

</div>

Hi there!

I’m currently in the process of building my personal website, which will contain a blog section. Within that blog section, I want to allow people to comment using Disqus, which is fairly easy to achieve with Zola.

The problem is that because of the way Disqus works, you only want it to be on the released site, not on local test builds. (I assume it is similar for things like Google Analytics, but I don’t really know.) For this reason, it’d be great, if one could tell the `zola build` command whether or not it is building the release or the development version.

This could be implemented similarly to the `base_url` as an option in the `config.toml` with an optional `--release` flag to override the value from the file. The value could be a bool or a string. The former would be a fairly simple system while the later would allow users much more flexibility (perhaps a company internal and a public version). As default values, I’d suggest `false` or something like “test” or “debug”.

A notable workaround to this feature, that works with the current version is setting an environment variable and checking it with teras `get_env()` built-in function.

If you are open to a feature like this, I’d be willing to implement it myself. However, I currently don’t have the time to do so, I could start in about two months.

What do you think?

---

<div class="post-metadata">

**Author:** ![southerntofu](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/southerntofu/32/189_2.png) [@southerntofu](https://zola.discourse.group/u/southerntofu)\
**Post date:** [April 29, 2020, 3:54pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/2 "2020-04-29T15:54:26Z")

</div>

Hi, could you maybe use `config.base_url` to check if you’re in a release build?

```auto
{% if config.base_url = "https://mydomain.net" %}
{# Disqus related stuff #}
{% endif %}

```

Your local test builds should use a different base\_url.

---

<div class="post-metadata">

**Author:** ![TeFiLeDo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tefiledo/32/631_2.png) [@TeFiLeDo](https://zola.discourse.group/u/TeFiLeDo)\
**Post date:** [April 29, 2020, 4:42pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/3 "2020-04-29T16:42:58Z")

</div>

I also thought of that but forgot to mention it in the original post.

The problem you have using this approach is that then you have hardcoded the `base_url` in multiple positions. If you want to move the site to another base\_url you have to update every single occurrence, so basically a violation of the [dry principle](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself).

Alternatively, you could store the release `base_url` in the `extra` section of the configuration, but you’d still have the value in two spots.

One other option I forgot to mention is to store the information on whether the build is a release in the configuration. However, this approach has another problem: if you want to build the site using CI, you’d have to manipulate the config before running Zola, which in my opinion is worse than using environment variables.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [April 29, 2020, 5:46pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/4 "2020-04-29T17:46:47Z")

</div>

I think Tera get\_env is the best bet there. I don’t think there should be different `zola build` mode built-in

---

<div class="post-metadata">

**Author:** ![southerntofu](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/southerntofu/32/189_2.png) [@southerntofu](https://zola.discourse.group/u/southerntofu)\
**Post date:** [April 30, 2020, 8:39pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/5 "2020-04-30T20:39:12Z")

</div>

> [@keats](#):
>
> I don’t think there should be different `zola build` mode built-in

How about having -c param for zola build/serve that configures the path to the config file? That would be simple and elegant i believe

---

<div class="post-metadata">

**Author:** ![TeFiLeDo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tefiledo/32/631_2.png) [@TeFiLeDo](https://zola.discourse.group/u/TeFiLeDo)\
**Post date:** [April 30, 2020, 10:21pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/6 "2020-04-30T22:21:12Z")

</div>

[That already exists.](https://www.getzola.org/documentation/getting-started/cli-usage/#build)

However, I think this is still worse than environment variables, because then you have to remember to update both files, which is a new source of possible errors.

---

<div class="post-metadata">

**Author:** ![southerntofu](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/southerntofu/32/189_2.png) [@southerntofu](https://zola.discourse.group/u/southerntofu)\
**Post date:** [April 30, 2020, 10:27pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/7 "2020-04-30T22:27:55Z")

</div>

> [@TeFiLeDo](#):
>
> [That already exists.](https://www.getzola.org/documentation/getting-started/cli-usage/#build)

Nice catch, did not see it in `zola build --help`

> [@TeFiLeDo](#):
>
> you have to remember to update both files

What about this in your build script?

```auto
sed 's/base_url = ".*"/base_url = "http:\/\/otherbase.url"/' config.toml > config.new.toml

```

Note sed requires escaping slashes

---

<div class="post-metadata">

**Author:** ![TeFiLeDo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/tefiledo/32/631_2.png) [@TeFiLeDo](https://zola.discourse.group/u/TeFiLeDo)\
**Post date:** [May 1, 2020, 12:13am UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/8 "2020-05-01T00:13:06Z")

</div>

> [@southerntofu](#):
>
> Nice catch, did not see it in `zola build --help`

It’s in `zola --help` because it’s a parameter of the program, not the subcommand (hence the importance of the position of the argument).

> [@southerntofu](#):
>
> What about this in your build script?
> 
> ```auto
> sed 's/base_url = ".*"/base_url = "http:\/\/otherbase.url"/' config.toml > config.new.toml
> 
> ```
> 
> Note sed requires escaping slashes

While this might work, it’s way easier for me to use environment variables. This approach would require me to add an extra build step, which is not really better than adding an environment variable. (And in my opinion, the solution with the environment variable is way more readable in the CI config.)

---

<div class="post-metadata">

**Author:** ![iEverX](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/ieverx/32/521_2.png) [@iEverX](https://zola.discourse.group/u/iEverX)\
**Post date:** [May 23, 2021, 4:41am UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/9 "2021-05-23T04:41:38Z")

</div>

Hugo has a --environment option. in serve mode, it default to ‘development’ and in build mode, default to ‘production’. It would be convenient if zola has this feature.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [May 23, 2021, 12:17pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/10 "2021-05-23T12:17:22Z")

</div>

We already have something like that ([zola/mod.rs at master · getzola/zola · GitHub](https://github.com/getzola/zola/blob/master/components/config/src/config/mod.rs#L89-L92)) but it isn’t exposed to the end user

---

<div class="post-metadata">

**Author:** ![iEverX](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/ieverx/32/521_2.png) [@iEverX](https://zola.discourse.group/u/iEverX)\
**Post date:** [May 24, 2021, 1:30pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/11 "2021-05-24T13:30:22Z")

</div>

seems that expososing to end user can be easily done. would you do this?

---

<div class="post-metadata">

**Author:** ![AntoniosBarotsis](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/antoniosbarotsis/32/1041_2.png) [@AntoniosBarotsis](https://zola.discourse.group/u/AntoniosBarotsis)\
**Post date:** [August 4, 2023, 5:59pm UTC](https://zola.discourse.group/t/distinguish-between-release-and-test-versions/398/12 "2023-08-04T17:59:15Z")

</div>

You can use [Tera’s](https://tera.netlify.app/docs/#get-env) `get-env` function.

In my blog I have included the following:

```plaintext
{% if get_env(name="env", default="dev") == "prod" %}
...
{% endif %}

```

This checks the `env` variable to see if it is equal to `prod` and only then includes the stuff inside the if block.

I am using Github Actions to build the site and I can easily set the `env` variable like so:

```plaintext
    - name: Build and deploy
      uses: shalzz/zola-deploy-action@master
      env:
        env: prod
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

```

Hope this helps 🙂
