Local testing of my Hugo site

Viewing/testing Hugo posts locally

I usually write posts and run a local instance of Hugo on a Docker container, so I can check spelling and post flow.

Most of the time, I notice something that needs to be changed prior to actually going live with a post on this site.

This is a basic walkthrough for myself on how to get a local Hugo instance setup and running.

High level overview

  • Run Docker container or virtual machine

  • Install Hugo

  • Install the Hugo-Clarity theme

  • Import, via git clone, the running website

  • Write/edit posts

  • Push to my local gitlab instance

Detailed steps

The version of Hugo I deployed in my Docker container is 0.107, so any testing, I want to be sure to use the same version.

  • Download Hugo Extended

    wget https://github.com/gohugoio/hugo/releases/download/v0.107.0/hugo_extended_0.107.0_linux-amd64.deb
    
  • Install Hugo

    sudo dpkg -i hugo_extended_0.107.0_linux-amd64.deb
    Selecting previously unselected package hugo.
    (Reading database ... 121100 files and directories currently installed.)
    Preparing to unpack hugo_extended_0.107.0_linux-amd64.deb ...
    Unpacking hugo (0.107.0) ...
    Setting up hugo (0.107.0) ...
    
  • Verify Hugo version

    hugo version
    hugo v0.107.0-2221b5b30a285d01220a26a82305906ad3291880+extended linux/amd64 BuildDate=2022-11-24T13:59:45Z VendorInfo=gohugoio
    
  • Create 'new' Hugo site:

    hugo new site nodinrogers.com
    
  • Run git init on the new site:

    cd nodinrogers.com/
    
    git init
    
  • Import the Hugo-Clarity theme:

    git submodule add https://github.com/chipzoller/hugo-clarity themes/hugo-clarity
    
  • Import running site from local gitlab instance:

    git clone ssh://git@gitlab.nodinrogers.com/tom/nodinrogers.com.git
    

    This will create a nodinrogers.com/nodinrogers.com directory structure, but otherwise, git will complain about the folder not being empty.

  • Move the cloned filed into the root (of the site) directory:

    pwd
    /home/tom/nodinrogers.com
    
    mv nodinrogers.com/* .
    

Finishing up and running Hugo

I create a Bash alias for running Hugo, as it needs to be available on the network, just not localhost:

echo "alias hugotest='hugo server --bind=0.0.0.0 --baseURL=http://10.10.10.184:1313'" >> ~/.bashrc

The above alias assumes the testing box has an IP of 10.10.10.184

Now I can easily run Hugo to see what new posts and/or site changes will look like without mucking with my main repro.

  • Run Hugo

    hugotest
    Start building sites …
    hugo v0.107.0-2221b5b30a285d01220a26a82305906ad3291880+extended linux/amd64 BuildDate=2022-11-24T13:59:45Z VendorInfo=gohugoio
    
                       | EN  | PT
    -------------------+-----+-----
      Pages            | 486 | 11
      Paginator pages  |  95 |  0
      Non-page files   | 150 |  0
      Static files     |  64 | 64
      Processed images |   0 |  0
      Aliases          | 196 |  5
      Sitemaps         |   2 |  1
      Cleaned          |   0 |  0
    
    Built in 6379 ms
    Watching for changes in /home/tom/nodinrogers.com/{archetypes,assets,content,data,i18n,layouts,static,themes}
    Watching for config changes in /home/tom/nodinrogers.com/config.toml, /home/tom/nodinrogers.com/config/_default, /home/tom/nodinrogers.com/config/_default/menus
    Environment: "development"
    Serving pages from memory
    Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
    Web Server is available at http://10.10.10.184:1313/ (bind address 0.0.0.0)
    Press Ctrl+C to stop
    

References

Github.com - gohugoio - hugo https://github.com/gohugoio/hugo/releases/tag/v0.107.0

Github.com - chipzoller - hugo clarity https://github.com/chipzoller/hugo-clarity