After playing around with this for a bit, I finally got it to work.
To give you an idea, my usual workflow when updating my theme is something like:
Make changes
Commit and push
Pull changes into my personal site, which uses the theme
Test to make sure I didn’t break anything
Commit pulled-in theme changes
Rinse and repeat
Since my theme (and many others out there) use an example site, I figured all the ingredients were there to build the site. And it would be nice to see a live demo with my immediate changes.
So why Netlify, and not some other CI? Well, Netlify is free, fast, and easy. Enough said in my book.
All you need to make this work is (1) connect your GitHub account to Netlify, and (2) add a netlify.toml file at the root of your theme repo. Here’s mine. And here’s an example:
I do it a slightly different way so that local builds work too, and theme components also work.
I don’t touch any of the Hugo CLI configs; I simply cd to the right dir and run hugo. Here’s my netlify.toml.
I then create a symlink to the theme in the exampleSite’s themes/ dir (similar to what you are doing with themesDir and theme). I create exampleSite/themes, cd to that dir and do ln -s ../.. my-theme-name, and I set theme = "my-theme-name" in exampleSite/config.toml.
With this in place, the same cd exampleSite && hugo works for local builds too.
Make sure you don’t have the theme line set in your exampleSite/config.toml , because it will conflict with the --theme option you pass in
This is wonderful, exactly what I was looking for. I’ve been maintaining 2 repos. One for the theme which includes the exampleSite and another for the live demo which contains a hugo root with the theme inside it.
It became annoying to deploy, and as I was copying the files from the live demo repo over into the theme repo I kept missing files.
I used the approach recommended by @zwbetz and it works great.
I can confirm even if you use --theme in the build command, if you have a theme key in your exampleSite/config.toml the Netlify deploy will fail.
Thanks to this post by @anthonyfok, I can now override the theme specified in the config file by setting the environment variable HUGO_THEME in netlify.toml
I can now override the theme specified in the config file by setting the environment variable HUGO_THEME
Most (if not all) Hugo config variables behave that way. Simply upcase a Hugo config and prefix with “HUGO_”, and you’ve got a valid env variable that you can use in lieu of that config variable.