How to represent books with chapters in Hugo?

Dear all

I’m trying to publish my own books with Hugo. Unfortunately, I’m unable so far to get it working.

As far as I understood, the book has to be a branch bundle, otherwise the chapters on the level below will be irrelevant:

/books (branch bundle, list template)
├/my-great-book (branch bundle, list template)
│├chapter-1 (leaf, single template)
│└chapter-2 (leaf, single template)

Is this correct? Is there a better way?

This approach however requires that authors are referenced on chapter level, not on book level. Of course, I can add “authors: [author1, author2]” in the front matter of the of the /books/my-great-book branch bundle… but it won’t link back from /authors/author1 or /authors/author2.

That’s not how most books work. I don’t want to list all chapters an author has written, but all books.

Hugo allows just as much content on branch bundle files as on leaf bundle files. Why would Hugo not treat authors of files (if provided in the front matter) the same way as authors provided in the front matter of files? This doesn’t make much sense to me.

Do you have any suggestions on how to properly implement the book/chapter logic with Hugo?

Many thanks in advance.

Found an ungly workaround:

Reference the authors of a book in one (and only one) of the book’s chapters. This will cause this one chapter to appear in the authors’ pages.

In order to show the book (instead of the chapter) on the authors’ profile, use the .Parent context (instead of the usual . context), i.e.:

{{ range .Pages }}
{{ .Parent.Title }}
{{ end }}

Still: It’s ugly and I wish there was a better way!

Hey there,

Just to clarify, Branch Bundle do not allow markdown files as Page Resources and it seems all you need here are markdown files (for your chapters). So I guess, you are just using a regular section for each book, and the chapters below are .RegularPages. But I would need to get a closer look at your content directory structure to be sure.

In other words, I don’t think you need a Branch Bundle here, but I might have misunderstood your use case.

If you need your Chapters to be published as individual pages (with their own URL etc…), then just a regular section would do.

If on the other hand, you don’t want your chapters published (but only printed on the book page) then you should go ahead and use Leaf Bundles (not Branch) for your books.

Why is this ugly?

Hi regis

Thanks for your response! Yes, I’m using sections for the books (on the second level, below a section called “books”) and regular pages for the chapters.

The way taxonomies work (on regular pages, not sections), I can’t assign authors or other taxonomies to the books (since they are sections and not regular pages). I only can do that for the chapters (since they are regular pages).

I find the workaround ugly because it requires the content editors to cooperate. It’s nothing that I as theme developer can control 100%.

What I’m trying to say is: Can Hugo please also support taxonomies on section pages? That would solve this. After all, you can put content, params and page resources in section pages (i.e. Why not support taxonomies, too?

I had never worked with Taxonomies on Section pages before and only found out about this problem just now.

I suggest you create a new Feature request issue on Hugo’s repo. I tend to agree with you, that this should be possible, but there might be other implications you and I did not figure out.

Wasn’t checking the issues on Github. Now that I did thanks to you, it turns out there already is an issue for that, reported last month:

Will accept your answer as solution. Thanks again, regis.

1 Like

Sections and taxonomies aside, you could use /content/books/example-book-title/ with cascading front matter. That’s how I’d do it.


As I had the same problem as @j2ms j2m and arrived on this page by searching on this forum, it may be interesting to note explicitly that it is now possible to assign a taxonomy to the index page of a Section:

1 Like

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