Need help on hugo -d docs

Hi everyone

I’m trying to set up a personal website using hugo (researcher theme) and deploy with Github Pages. I have succeed building the webpage many times. But after I updated a blog, the deployment failed…

The hugo environement is as:

hugo v0.118.1-0eb480aa1d06653803175e3fdfad5dbf5fc26f9b+extended linux/amd64 BuildDate=2023-08-31T09:42:31Z VendorInfo=gohugoio
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.21.0"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.2.4"

On my computer, the command hugo server -D succeeds and the content is same as what I wrote.

root@Xinkai-Thinkpad:/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io# hugo server -D
Watching for changes in /mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/{archetypes,content,data,layouts,static,themes}
Watching for config changes in /mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/config.toml
Start building sites …
hugo v0.118.1-0eb480aa1d06653803175e3fdfad5dbf5fc26f9b+extended linux/amd64 BuildDate=2023-08-31T09:42:31Z VendorInfo=gohugoio


                   | EN
-------------------+-----
  Pages            | 11
  Paginator pages  |  0
  Non-page files   |  0
  Static files     | 87
  Processed images |  0
  Aliases          |  0
  Sitemaps         |  1
  Cleaned          |  0

Built in 1620 ms
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://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

But when I want to generate a static page using hugo -d docs, it failed and the files in the docs directory is not same as the content directory.

root@Xinkai-Thinkpad:/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io# hugo -d docs
Start building sites …
hugo v0.118.1-0eb480aa1d06653803175e3fdfad5dbf5fc26f9b+extended linux/amd64 BuildDate=2023-08-31T09:42:31Z VendorInfo=gohugoio

ERROR render of "page" failed: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/researcher/layouts/_default/baseof.html:15:12": execute of template failed: template: _default/single.html:15:12: executing "_default/single.html" at <partial "consent.html" .>: error calling partial: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/researcher/layouts/partials/consent.html:50:50": execute of template failed: template: partials/consent.html:50:50: executing "partials/consent.html" at <where .Site.Data.consent.items "is_functional" false>: error calling where: can't iterate over <nil>
ERROR render of "home" failed: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/researcher/layouts/_default/baseof.html:15:12": execute of template failed: template: index.html:15:12: executing "index.html" at <partial "consent.html" .>: error calling partial: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/researcher/layouts/partials/consent.html:50:50": execute of template failed: template: partials/consent.html:50:50: executing "partials/consent.html" at <where .Site.Data.consent.items "is_functional" false>: error calling where: can't iterate over <nil>
Total in 29412 ms
Error: error building site: render: failed to render pages: render of "page" failed: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/researcher/layouts/_default/baseof.html:15:12": execute of template failed: template: _default/single.html:15:12: executing "_default/single.html" at <partial "consent.html" .>: error calling partial: "/mnt/c/Users/Xinkai Wang/Documents/Coding Files/Wang-Xinkai.github.io/themes/

I’ve searched for the reason and check the corresponding file. But changing .Site to self.Site or site does not work.

consent.html:50: const scripts = [];{{ range $index, $item := (where .Site.Data.consent.items "is_functional" false) }}

Oh, there was ERROR on render of ‘taxonomy’ failed. I solved it by adding disableKinds = ["taxonomy", "term"] in the config.toml. But I cannot add page here, which resulted in the failed construction of all pages.

I’d appreciate it if someone could offer me some advice on the problem and how to fix it.

Thanks a lot!

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

sorry for that! The repo is Wang-Xinkai/Wang-Xinkai.github.io: Personal website and thanks for your kind help!

It looks like you have published the site into the root of your project (source).

Not actually… I set the docs directory as the Github page source:

Maybe it is because hugo server -D I used in editing the page? This command works well, the command hugo -d docs generate the error above.

Then why is your repository polluted with build artifacts?


oops…maybe I executed hugo server -d without specifying the destination? I am not sure what is the reason (I am new to Hugo framework). Is it the reason for the error? I need to delete the artifacts in the source directory?

Yeah, you need to clean things up. Your project structure should look something like this, though some of the directories are optional:

https://gohugo.io/getting-started/directory-structure/#site-skeleton

Add public/ to your .gitignore file so that it is not stored in your repository.

Also, I strongly recommend following this guide for hosting on GitHub pages:

https://gohugo.io/hosting-and-deployment/hosting-on-github/

Let GitHub build the site for you.

I’ve cleaned things up and pushed the changes. However, hugo -d docs still generate the same error…

BTW, I will set the github workflow when I fix the bug. Thanks for your advice on it.

Where’s the data directory?
Why do you have a sass directory in the root of the project?
Your resources directory is has things that shouldn’t be there. Just delete it. It will be recreated as needed.

Moreover, I’ve set up the workflow based on your advice, but it generates same error on Github

Again, where is it? The messages are about a missing data directory, a file inside of it named content, containing an “items” array, with a key “is_functional”.

And you need to be careful of the .gitignore syntax. Should be this (with trailing slashes):

public/
resources/
.hugo_build.lock

I checked it locally. There is a data directory on my computer:

But the data directory is empty. I will check the template repo and add the corresponding file in the data directory.

I’ve checked the theme repo ( ankitsultana/researcher: A jekyll based resume template (github.com)) It does not have a ``data``` directory. So I donot know whether I delete the content of data directory by mistake…

Should I rebuild the site from scratch to recover the data directory?

Your data directory is probably empty. Empty directories are not added to Git repositories.

Looks like the theme author added a cookie consent feature without (a) adding a sample data file, (b) updating the documentation, and (c) testing.

See https://github.com/ojroques/hugo-researcher/pull/34

You need to take this up with the theme author, or use a different theme:
https://github.com/ojroques/hugo-researcher/issues

Thanks a lot! So in a nutshell, the root cause is that the template misses the necessary content in data directory? what a pity… But why could I deploy it locally without data but fails to deploy statically? It is confusing lol

Anyway, I will take this up with the theme author or consider changing a theme. Thanks again

I reset the theme repo to the last commit where the consent feature is not used. And the build is successful.

Thanks, Joe!

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