Setting HUGO_MODULE_REPLACEMENTS uses go.mod version without error

The module github.com/willfaught/paige@v0.58.1 is a theme. It has an exampleSite with a go.mod:

module github.com/willfaught/paige/exampleSite

go 1.20

require github.com/willfaught/paige v0.58.0 // indirect

When I try to build/run exampleSite using the local copy of the theme, it uses the published version of the theme.

For example, http://localhost:1313 shows a home page with the title “Paige”. If you modify the local theme copy to put a “foo” word below the title:

--- a/layouts/partials/paige/metadata.html
+++ b/layouts/partials/paige/metadata.html
@@ -19,6 +19,7 @@
 <div class="w-100" id="paige-metadata">
     {{ with $title }}
         <h1 class="fw-bold text-center" id="paige-title">{{ if $link }}<a href="{{ $link }}">{{ . }}</a>{{ else }}{{ . }}{{ end }}</h1>
+        <p>foo</p>
     {{ end }}
 
     {{ with $description }}

and then set HUGO_MODULE_REPLACEMENTS and HUGO_THEMESDIR, nothing changes at http://localhost:1313:

~/Developer/paige/exampleSite
❯ env HUGO_MODULE_REPLACEMENTS='replace github.com/willfaught/paige -> paige' HUGO_THEMESDIR=../.. hugo server

For what it’s worth, hugo mod graph doesn’t show any changes, but I’m not clear on whether that’s expected:

❯ env HUGO_MODULE_REPLACEMENTS='replace github.com/willfaught/paige -> paige' HUGO_THEMESDIR=../.. hugo mod graph
github.com/willfaught/paige/exampleSite github.com/willfaught/paige@v0.58.0

I also tried the absolute path approach:

~/Developer/paige/exampleSite
❯ env HUGO_MODULE_REPLACEMENTS='replace github.com/willfaught/paige -> /Users/Will/Developer/paige' hugo server

There’s no error at all. Mapping to a non-existent directory also runs without error:

~/Developer/paige/exampleSite
❯ HUGO_MODULE_REPLACEMENTS='replace github.com/willfaught/paige -> /foo' hugo server

I’m not sure what I’m missing.

You need to remove the “replace”. Try:

env HUGO_MODULE_REPLACEMENTS='replace github.com/willfaught/paige -> paige' HUGO_THEMESDIR=../.. hugo server

On a related note, the above setting was added before Go got workspace support.

See https://github.com/gohugoio/hugoDocs/blob/master/hugo.work

As an example, when I do theme changes on the Hugo theme, I do this from the hugoDocs repo:

 HUGO_MODULE_WORKSPACE=hugo.work hugo server --ignoreVendorPaths "**"
1 Like

Apparently I am blind. Thanks for the correction, and the workspace tip!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.