OK so I think I’ve got a handle on the different ways to use a theme, so I thought I’d post this to try to summarize it for people after me so they don’t have to do as much legwork (hopefully). This summary assumes you’re using git
. Please feel free to correct what I’m saying here - I have no interest in looking like a git or hugo expert, I just want to save people time.
-
Using
git clone
.
This clones a copy of a git repository to a subdirectory in the/themes
folder.
Positives: easy and quick
Negatives: Your repository for your website will have a copy of the theme inside of it. -
Using
git submodule
.
This clones a copy of a git repository to a subdirectory in the/themes
folder, but registers it with the website repository using a.gitmodules
file.
Positives: You’ve now made clear to git the repository inside of another repository, so the dependencies are now clear.
Negatives: git commands to clone your website repository are a little more complicated to do it recursively, etc. Seems to be somewhat unpopular on the web. -
Using
git subtree
.
This clones a copy of a git repository to a subdirectory in the/themes
folder, using a different approach than submodules to register its relationship to the repository above.
https://www.atlassian.com/git/tutorials/git-subtree
Positives: It seems to simplify the later cloning of your website repository, as the consumer of your repository doesn’t need to know about the subrepository.
Negatives: If you are developing the theme at the same time, it seems that commits are little more complicated, and it’s best practice to split the commits across repository boundaries to keep the messages clear. -
Move the theme directory.
You can have a theme repository cloned in another folder, and usethemesDir = "../.."
inconfig.toml
, for example, to point to the proper folder above the theme repository.
Positives: Completely separate repositories, easy to develop your website and the theme at the same time. Works fine for local testing.
Negatives: Doesn’t translate to deployment. -
Use Hugo modules.
Use Hugo Modules | Hugo
You can direct Hugo to retrieve and use the theme repository during deployment.
Positives: Once set up, it works fine and keeps the build pointing to whichever version of the theme you want.
Negatives: I believe you are limited to retrieving released versions of a theme - ie those that have been tagged in git. This makes it hard to use for theme development. -
Point directly at the theme on github.
This one isn’t clear to me yet … I’ve asked @pointyfar if he could clarify what he said over here, and I’m sure he’ll be able to help. It seems like he has had success doing this inconfig.toml
:theme = "github.com/username/themeName"
.
Positives: A useful solution for production, and also seems to be an optimal solution for testing out a theme repository in a production environment prior to labeling and releasing it. This may seem to be a minor draw, but it’s what is holding me back right now.
Negatives: I can’t seem to get it to work.
I’d love to hear any advice folks would be willing to give on any of these … thanks in advance.
Carmine