Incomplete generation of a new theme

#1

Dear community

When I create a new theme with hugo new theme [name] then I get a base template which looks like this:

<html>
    {{- partial "head.html" . -}}
    <body>
        {{- partial "header.html" . -}}
        <div id="content">
        {{- block "main" . }}{{- end }}
        </div>
        {{- partial "footer.html" . -}}
    </body>
</html>

The head partial doesn exists. Also the index.html template doesn’t define main. In my opinion the generation of a new theme is incomplete, because I expect when I use a generator that it works out of the box and I can start customizing instead of repairing. Should I send a PR for this? :slight_smile:

#2

My suggestion is to discuss what you’d put as the default scaffolding for all new Hugo users.

#3

I wanted to point out the hugo new theme “will scaffold the beginnings of a new theme for you to get you on your way.” It isn’t a generator. But that is the point, as we want generators to be opinionated and solve a lot of pain points for a use case. The problem Hugo is solving is helping new folks learn about the basic practice of constructing a theme.

Currently, Hugo is geared for people that build web things. A theme generator will make it more accessible to more people. I think it makes sense to keep Hugo lean and doing what it does, and building tools up and around it. A generator fits the tool category really well.

To make sure this isn’t a technical bug, could you tree out your new theme directory. Is it the case that your head partial is empty, or does it not exist?

#4

Here is a step by step explanation:

  1. Create a new Hugo site with hugo new site incomplete
    Congratulations! Your new Hugo site is created in /tmp/incomplete.
  2. Change to the folder of the new site with cd incomplete
  3. Create a new theme with hugo new theme example
    Creating theme at /tmp/incomplete/themes/example
  4. Set the theme of the site to example in /tmp/incomplete/config.toml with echo "theme = \"example\"" >> config.toml
  5. Create some content with echo "Hello World" >> content/_index.md
  6. It wont work yet, because we need to define “main” in themes/example/layouts/index.html.
    {{ define "main" }}
    {{ end }}
  7. It still won’t work, because the partial head.html is missing. You’ll receive an error when you run hugo serve.
Building sites … ERROR 2018/06/24 01:04:23 Error while rendering "home" in "": template: index.html:2:8: executing "index.html" at <partial "head.html" ...>: error calling partial: Partial "head.html" not found
Total in 2 ms
Error: Error building site: logged 1 error(s)

The tree looks like this now:

.
├── archetypes
│   └── default.md
├── config.toml
├── content
│   └── _index.md
├── data
├── layouts
├── static
└── themes
    └── example
        ├── archetypes
        │   └── default.md
        ├── layouts
        │   ├── 404.html
        │   ├── _default
        │   │   ├── baseof.html
        │   │   ├── list.html
        │   │   └── single.html
        │   ├── index.html
        │   └── partials
        │       ├── footer.html
        │       └── header.html
        ├── LICENSE
        ├── static
        │   ├── css
        │   └── js
        └── theme.toml

14 directories, 13 files

To make hugo new theme more intuitive I would integrate the last two steps into the theme generation.

1 Like
#5

I am not receiving that error, so you might want to show your project’s code, as suggested: Requesting Help

If you want to know how the current template came about, there is https://github.com/gohugoio/hugo/issues/3576.

If you want to suggest making changes, I recommend you wait here for a reply or start an issue with your proposals.

If you want to figure out the issue you are having with that partial, share your code and all the facts of your environment.

#6

Honestly I feel a bit offended by you @maiki. It took me quite much time to write this step by step description of my observation and you just send me a tutorial how I should Request for Help. Of course I can share the code with you, but I didn’t add anything extra than what Hugo generated except the _index.md as I described.

Don’t worry about the error I understand it. What I’m trying here is to improve Hugo, because I think the generator could do more to be intuitive. So new users would run into less walls.

Here is the code which was produced after this 7 steps I described before: https://github.com/openscript/hugo-incomplete

Maybe our version of hugo is different? We are using Hugo Static Site Generator v0.42.1 linux/amd64 BuildDate: 2018-06-13T20:49:30+0200.

#7

Should I continue from here or give this topic up?

#8

If you have a PR idea, then maybe make an issue in the github, and debate it there first.

At first, perhaps hugo new theme was designed in an “un-opinionated” way since there are a few ways you can design themes, or, it is simply that its defaults were decided before blocks were introduced. This project is after all staffed by volunteers so, it’s just a matter of time and desire to do something, and priority setting…

I authored Requesting Help, because we get tons of vague requests for help without much info at all. It helps us a bit by saving time repeating the same thing.

But it appears that you’re talking more about changing the way hugo itself works, rather than asking for help with hugo usage.

Personally, I agree with making the hugo new theme use blocks and have some typical components from the start.

#9

Thank you for your response.

I like to get things done and move quickly, but I also agree that precise and careful engineering is more valuable than hasty reactions.

In this case I feel quite sure about what to do and I don’t see a point in discussing it again in an issue, so I just created an PR here: https://github.com/gohugoio/hugo/pull/4877

Hopefully it helps someone :slight_smile: