[Assets Management] Is there a variable to know when Hugo is run with "server"?

I want to create a shortcode to render my images via Cloudinary (after reading this thread).

For the sake of simplicity, I want to use the Auto-Fetch feature from cloudinary which only requires to prepend my images URLs with their URL. Creating a shortcode will be pretty easy.

The only thing I’m missing is if there is a variable that the shortcode can use to decide if the current state is ‘Dev’ (ran via hugo server) or ‘Prod’ (ran via hugo). So far I’m planning to use .Site.BaseURL and compare with http://localhost:1313 to decide if I’m on my machine or not.

Is there anything better than that?

Feel free to edit my title if you find some clearer way to express my question :slightly_smiling:

I think there is more than one way to do this (including checking for buildDrafts if you use that flag for local dev), but have you considered using an environmental variable?


Thanks, great suggestion :+1:.

1 Like