thegeeklab / hugo-geekdoc

Hugo theme made for documentation

Home Page:https://geekdocs.de

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

404 render error

mschirrmeister opened this issue · comments

Hello,

I am running into an issue where I get an error when it tries to render the 404. Is there still something I need to configure to get it working? Or is this a bug?

Steps to reproduce

hugo new site demosite
cd demosite/
mkdir -p themes/hugo-geekdoc/
curl -L https://github.com/thegeeklab/hugo-geekdoc/releases/latest/download/hugo-geekdoc.tar.gz | tar -xz -C themes/hugo-geekdoc/ --strip-components=1

Adding the following to hugo.toml.

baseURL = "http://localhost"
# languageCode = 'en-us'
title = "test"
theme = "hugo-geekdoc"

pluralizeListTitles = false

# Geekdoc required configuration
pygmentsUseClasses = true
pygmentsCodeFences = true
disablePathToLower = true

# Required if you want to render robots.txt template
enableRobotsTXT = true
hugo new content _index.md

hugo
Start building sites …
hugo v0.122.0-b9a03bd59d5f71a529acb3e33f995e0ef332b3aa+extended darwin/amd64 BuildDate=2024-01-26T15:54:24Z VendorInfo=gohugoio

Total in 80 ms
Error: error building site: render: render of "404" failed: "/Users/marco/Public/demosite/themes/hugo-geekdoc/layouts/404.html:18:9": execute of template failed: template: 404.html:18:9: executing "404.html" at <partial "site-header" (dict "Root" . "MenuEnabled" false)>: error calling partial: "/Users/marco/Public/demosite/themes/hugo-geekdoc/layouts/partials/site-header.html:16:60": execute of template failed: template: partials/site-header.html:16:60: executing "partials/site-header.html" at <.Root.Site.Home.Permalink>: error calling Permalink: runtime error: invalid memory address or nil pointer dereference

Hello, which hugo version do you use?

0.122. You can see it at the last command.

Thanks missed that. The issue is, that the empty home page created by hugo new content _index.md has draft = true set by default. You can either use hugo --buildDrafts or remove the draft flag from the home page.

Thank you for the update. I did not try to change or remove each of the lines in the header.
But what you wrote matches then with what I saw last night, when I created new content while I had enableGitInfo = true set in the config. I got a different, but the _index.md was created with a yaml header and the draft option was not there.

After setting enableGitInfo to false to get rid of the git error, the hugo run was fine.

Is it more of a hugo problem, or still something that can be fixed in the theme?

This is just an intentional error, I would say. In the theme templates, we use the Hugo built-in variable .Site.Home.Permalink. If no home page exists (e.g. because it is marked as draft and the build was created without draft pages), an error occurs. We can try to catch this error in the theme, but a project without a home page is very unlikely, and we would suppress an error silently that would help users to detect the missing home page.

I have not much experience with Hugo yet. Just stared using it and all files that were created had draft. Did not think about changing it yet.

Based on that, I guess one only runs into that problem at the very beginning, when trying to build with all the defaults.

Thank you very much again for the quick response.
Feel free to close the issue.

Fair point. I think we can at least improve the getting started documentation and explain why we use -D flag in step 5 and what's required for the theme to work.