theNewDynamic / gohugo-theme-ananke

Ananke: A theme for Hugo Sites
https://gohugo-ananke-theme-demo.netlify.com/
MIT License
1.09k stars 1.12k forks source link

Fix rendering breakage introduced in #665 #685

Closed ramiro closed 2 months ago

ramiro commented 2 months ago

A bare bones setup of two pages and two posts gets broken because of a template change missed in #665

Fatal error message in readable form:

ERROR render:
failed to render pages:
render of "home" failed: "themes/ananke/layouts/index.html:48:23":
execute of template failed:
template:
index.html:48:23:
executing "main" at <.Site.GetPage>: can't evaluate field Site in type string

Steps to reproduce:

hugo new site quickstart
cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo "theme = 'ananke'" >> hugo.toml
echo -e "+++\ntitle='Home'\n+++\n\nMain page" > content/_index.md
echo Foo. > content/page1.md
echo Bar. > content/page2.md
mkdir -p content/post
echo "First post." > content/post/post1.md
echo "Second post." > content/post/post2.md
hugo server

Output:

Watching for changes in quickstart/{archetypes,assets,content,data,i18n,layouts,static,themes}
Watching for config changes in quickstart/hugo.toml, quickstart/themes/ananke/config.yaml
Start building sites …
hugo v0.125.3-474c4c02212cf97712c6fbf4159c68822ea6e078+extended darwin/amd64 BuildDate=2024-04-22T17:18:35Z VendorInfo=brew

Built in 67 ms
Error: error building site: render: failed to render pages: render of "home" failed: ".../quickstart/themes/ananke/layouts/index.html:48:23": execute of template failed: template: index.html:48:23: executing "main" at <.Site.GetPage>: can't evaluate field Site in type string
netlify[bot] commented 2 months ago

Deploy Preview for gohugo-ananke-theme-demo canceled.

Name Link
Latest commit bbd9d80f8d8aa0052ecca099ec0c750ec11c950d
Latest deploy log https://app.netlify.com/sites/gohugo-ananke-theme-demo/deploys/662a2d2d193b5c00082b9a68
deining commented 2 months ago

If you run a preview of the example site, you will encounter the same error.

jmooring commented 2 months ago

We just had the first report of this on the Hugo forum. Hugo's quick start guide currently instructs users to install Ananke, so they're going to run into a dead end.

I haven't reviewed this PR or #665, but in the short term I'd be inclined to simply revert f34c219436ab1c3b116f8706a521d40c4b8693b9.

vlcinsky commented 2 months ago

I can confirm, that this (very simple) PR fixed the issue. In my case, when I had 4 and more pages in a section, the generation was failing (as it attempts to do some "see all pages" etc.). This PR fixed the issue.

oupala commented 2 months ago

I can testify that this issue breaks the website rendering.

In the meantime, is there a way to statically set the version of the theme I use in order to fix the build?

jmooring commented 2 months ago

@oupala If you've added the theme to your Hugo project as a git submodule, you can:

cd themes/ananke/
git checkout 0d06863
oupala commented 2 months ago

@oupala If you've added the theme to your Hugo project as a git submodule, you can:

I don't think I have added the theme as a submodule

I'm using the following method to add the theme:

hugo mod get -u github.com/theNewDynamic/gohugo-theme-ananke

with a go.sum and a go.mod file

I think the go.mod file is referencing a specific version:

require github.com/theNewDynamic/gohugo-theme-ananke v0.0.0-20231122160523-91df000ca827 // indirect

jmooring commented 2 months ago

@oupala

hugo mod get -u github.com/theNewDynamic/gohugo-theme-ananke@0d06863

Your go.mod file should then look like:

require github.com/theNewDynamic/gohugo-theme-ananke v0.0.0-20240418152324-0d068637ccd8 // indirect
oupala commented 2 months ago

@jmooring It looks like this workaround does not work:

$ hugo mod get -u $THEME_URL
hugo: collected modules in 1467 ms
go: downloading github.com/theNewDynamic/gohugo-theme-ananke v0.0.0-20240418152630-f34c219436ab
go: upgraded github.com/theNewDynamic/gohugo-theme-ananke v0.0.0-20240418152324-0d068637ccd8 => v0.0.0-20240418152630-f34c219436ab

and I still get the same error in the build:

Error: error building site: render: failed to render pages: render of "home" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/the!new!dynamic/gohugo-theme-ananke@v0.0.0-20240418152630-f34c219436ab/layouts/index.html:48:23": execute of template failed: template: index.html:48:23: executing "main" at <.Site.GetPage>: can't evaluate field Site in type string
ramiro commented 2 months ago

@oupala please don't hijack this issue's comments for personalized support for deploying Hugo and its themes. All the other subscribers genuinely interested in the actual issue receive a notification with each post

thesamrooney commented 2 months ago

I ran into the same issue (sorry oupala not the same one you have) and independently found the same solution. This PR fixed the issue and is an easy win.

regisphilibert commented 2 months ago

Sorry about the delay. And thanks for the fix.