If I read it correctly, it’s the rendering time of my menu which is very long. I have a recursive fonction that build the menu depending of the folder structure. I’ve borrowed it from the hugo book theme with some light modifications.
It works fine on my computer most of the times - I had once or two a build failed, with no apparent reasons.
This is the code of partials/menu.html:
<!--
https://github.com/alex-shpak/hugo-book/blob/master/layouts/partials/docs/menu-filetree.html
-->
{{ $section := .Section }}
<h3>{{ with .Site.GetPage "section" $section }}{{ .Title }}{{ end }}</h3>
{{ with .Site.GetPage $section }}
{{ template "section-children" (dict "Section" . "CurrentPage" $) }}
{{ end }}
{{ define "section-children" }}{{/* (dict "Section" .Section "CurrentPage" .CurrentPage) */}}
<ul>
{{ range (where .Section.Pages "Params.pagehidden" "ne" true) }}
{{ if .IsSection }}
<li {{- if .Params.BookFlatSection }} class="book-section-flat" {{ end -}}>
{{ template "page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
{{ template "section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
</li>
{{ else if and .IsPage .Content }}
<li>
{{ template "page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
</li>
{{ end }}
{{ end }}
</ul>
{{ end }}
{{ define "page-link" }}{{/* (dict "Page" .Page "CurrentPage" .CurrentPage) */}}
{{ $current := eq .CurrentPage .Page }}
{{ $ancestor := .Page.IsAncestor .CurrentPage }}
{{ if .Page.Params.menuOff }}
<span>
{{- partial "doc-titles" .Page -}}
</span>
{{ else }}
{{ if $current }}
<span class="active">{{ partial "doc-titles" .Page }}</span>
{{ else }}
<a href="{{ .Page.RelPermalink }}" class="{{ if $current }}active{{ end }}">
{{- partial "doc-titles" .Page -}}
</a>
{{ end }}
{{ end }}
{{ end }}
This is all about cache setup. This is how the Hugo docs config looks like:
[caches]
[caches.getjson]
dir = ":cacheDir/:project"
maxAge = -1
[caches.getcsv]
dir = ":cacheDir/:project"
maxAge = -1
[caches.images]
dir = ":cacheDir/images"
maxAge = "1440h"
[caches.assets]
dir = ":resourceDir/_gen"
maxAge = -1
When you put your image cache below :cacheDir it will work out of the box on Netlify. If the HUGO_CACHEDIR env var is not set, Hugo will detect that it’s running on Netlify and set it to a directory that will be restored on next build.
Thank you very much for the rapidity and clarity of your help!
jmooring, when I remove the resources folder, in fact the build time is 1 minute on my computer.
Thank you bep, I added the caches directives in my config.toml and indeed now it takes 375ms to build, yeahh !
About cache, in the hugo doc, it says to include the resource directory in source control. Is it an equivalent method ? Or the one you propose is better ?