Hugo : Creating a new site from Template
Overview
Using Hugo for a while now, I realized I was constantly copy pasting code from one website to the other. To prevent this I have started creating my own template. I want to push all my functionnalities there, and when required, be able to pull the new version into my existing sites.
Method 1 : Git Submodule
|
|
Edit the config.toml
file and update the theme.
|
|
Then save the current status.
|
|
To check for updates on the submodules use git status
.
Pulling latest version of the Theme one of those commands will synchronize the repositories:
|
|
Or if the submodule were not Initialized properly, use
|
|
Those commands will pull the current project and all the submodules.
Project Initialization / cloning
When cloning the project, make sure to do the following :
|
|
Project use with Github and Netlify
The issue in Netlify during the automatic deployment is related to the submodule not being retrieve, so all the default layout, css, scripts, etc… are missing when building the Hugo static site.
This is a sample of the error retrieved :
1:49:02 PM: Starting to prepare the repo for build
1:49:02 PM: Preparing Git Reference refs/heads/master
1:49:04 PM: Failed during stage 'preparing repo': Error checking out submodules: Submodule 'themes/hugo-theme-fha' (https://git.fhahome.dev/Template/hugo-theme-fha.git) registered for path 'themes/hugo-theme-fha'
Cloning into '/opt/build/repo/themes/hugo-theme-fha'...
fatal: could not read Username for 'https://git.fhahome.dev': No such device or address
fatal: clone of 'https://git.fhahome.dev/Template/hugo-theme-fha.git' into submodule path '/opt/build/repo/themes/hugo-theme-fha' failed
Failed to clone 'themes/hugo-theme-fha'. Retry scheduled
Cloning into '/opt/build/repo/themes/hugo-theme-fha'...
fatal: could not read Username for 'https://git.fhahome.dev': No such device or address
fatal: clone of 'https://git.fhahome.dev/Template/hugo-theme-fha.git' into submodule path '/opt/build/repo/themes/hugo-theme-fha' failed
Failed to clone 'themes/hugo-theme-fha' a second time, aborting
: exit status 1: Submodule 'themes/hugo-theme-fha' (https://git.fhahome.dev/Template/hugo-theme-fha.git) registered for path 'themes/hugo-theme-fha'
Cloning into '/opt/build/repo/themes/hugo-theme-fha'...
fatal: could not read Username for 'https://git.fhahome.dev': No such device or address
fatal: clone of 'https://git.fhahome.dev/Template/hugo-theme-fha.git' into submodule path '/opt/build/repo/themes/hugo-theme-fha' failed
Failed to clone 'themes/hugo-theme-fha'. Retry scheduled
Cloning into '/opt/build/repo/themes/hugo-theme-fha'...
fatal: could not read Username for 'https://git.fhahome.dev': No such device or address
fatal: clone of 'https://git.fhahome.dev/Template/hugo-theme-fha.git' into submodule path '/opt/build/repo/themes/hugo-theme-fha' failed
Failed to clone 'themes/hugo-theme-fha' a second time, aborting
: exit status 1
1:49:04 PM: Error checking out submodules: Submodule 'themes/hugo-theme-fha' (https://git.fhahome.dev/Template/hugo-theme-fha.git) registered for path 'themes/hugo-theme-fha'
Cloning into '/opt/build/repo/themes/hugo-theme-fha'...
fatal: could not read Username for 'https://git.fhahome.dev': No such device or address
fatal: clone of 'https://git.fhahome.dev/Template/hugo-theme-fha.git' into submodule path '/opt/build/repo/themes/hugo-theme-fha' failed
Failed to clone 'themes/hugo-theme-fha'. Retry scheduled
Add the required inform,ation to .gitmodules
file.
Update the netlify.toml
to retrieve the submodules used in the project.
|
|
Method 2 : Git Subtree
First method I have tried, but on Windows 11 with VS Code, I had a very strange behaviour when updating an existing site, although my content website and the theme were in their own folders, everything was mixed up.
This exemple shows how to create a new project and adding the Theme as a Git Submodule.
On an existing project, the git subtree add
command can be run as a standalone.
|
|
Edit the config.toml
file and update the theme.
|
|
Then save the current status.
|
|