How to generate plain text files with different content for different environments

Hi,

I ran into a problem where I can see no obvious solution.

Situation:

  • I have set up Hugo for GitHub pages.
  • I use two Hugo environments (development and production) with different config files.
  • I generate the development data into docs and publish it to GitHub to be served as test.myblog.com.
  • I generate the production data into ../public, which is a different repo. I push this repo to GitHub to be served under myblog.com.

Problem:
The CNAME file that GitHub requires must contain the custom domain, but this domain can have two different values. Yet, when I put the CNAME file into the static folder it obviously is the same file in both Hugo environments.

Question:
How can I generate the CNAME contents from the baseURL setting in the active config file?

That is, for hugo -e development, CNAME should contain the base URL from the development config file, that is, test.myblog.com, and when running hugo -e production, CNAME should contain myblog.com from the production config file.

Templates seem to be restricted to particular output types, e.g. .html or .xml files, hence no option here if I am not wrong.
Or did I overlook something obvoius?

It can be so simple!

Config files have a staticDir setting… problem solved.

Edit: Or maybe it is not the solution. Unlike config files, the content in the static dirs from the dev or prod config files does not get merged with the default static dir. Hence I would have to duplicate all static files into the environment-specific static files.

Editd 2: Just found that staticDir is a multi-value variable. Problem solved again! :crazy_face:

2 Likes