Hi there!
Am trying to run my hugo-supported page with the academic theme. Last time I checked up on it, it was running and it was at the end of March 2021. Today I wanted to add some information on it and I had to face the following error message:
Error: Error building site: failed to render pages: render of "home" failed: execute of template failed:
template: index.html:18:8: executing "main" at <partial "widget_page.html" .>: error calling partial:
execute of template failed: template: partials/widget_page.html:79:9: executing
"partials/widget_page.html" at <partial $widget_path $widget_args>: error calling partial:
"/Users/atantos/Documents/LAL2A/Page/layouts/partials/widgets/experience.html:40:23": execute of
template failed: template: partials/widgets/experience.html:40:23: executing
"partials/widgets/experience.html" at <.date_end>: can't evaluate field Format in type *errors.errorString
I have not updated hugo for some time by now and the version I have on my machine is definitely not a version 0,8X. Moreover, the hugo academic template has been updated many times since March and apparently I never followed the breaking changes. However, the page was up and running last March and I tried to run earlier version of Hugo, just in case. I tried running all hugo version back to 0.79 and I kept getting the same error.
Am far from an expert in Hugo and the error is probably due to some naive mistake. However, I did not change anything to the code and there is no way I can figure out what is happening.
Here is the experience.html file:
{{ $ := .root }}
{{ $page := .page }}
<!-- Experience widget -->
<div class="row">
<div class="col-12 col-lg-4 section-heading">
<h1>{{ with $page.Title }}{{ . | markdownify }}{{ end }}</h1>
{{ with $page.Params.subtitle }}<p>{{ . | markdownify }}</p>{{ end }}
</div>
<div class="col-12 col-lg-8">
{{ with $page.Content }}{{ . }}{{ end }}
{{ if $page.Params.experience }}
{{ $exp_len := len $page.Params.experience }}
{{ range $idx, $key := sort $page.Params.experience ".date_start" "desc" }}
<div class="row experience">
<!-- Timeline -->
<div class="col-auto text-center flex-column d-none d-sm-flex">
<div class="row h-50">
<div class="col {{if gt $idx 0}}border-right{{end}}"> </div>
<div class="col"> </div>
</div>
<div class="m-2">
<span class="badge badge-pill border {{if not .date_end}}exp-fill{{end}}"> </span>
</div>
<div class="row h-50">
<div class="col {{if lt $idx (sub $exp_len 1)}}border-right{{end}}"> </div>
<div class="col"> </div>
</div>
</div>
<!-- Content -->
<div class="col py-2">
<div class="card">
<div class="card-body">
<h4 class="card-title exp-title text-muted mt-0 mb-1">{{.title | markdownify | emojify}}</h4>
<h4 class="card-title exp-company text-muted my-0">
{{- with .company_url}}<a href="{{.}}" target="_blank" rel="noopener">{{end}}{{.company | markdownify | emojify}}{{with .company_url}}</a>{{end -}}
</h4>
<div class="text-muted exp-meta">
{{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }} –
{{ if .date_end}}
{{ (time .date_end).Format ($page.Params.date_format | default "January 2006") }}
{{else}}
{{ i18n "present" | default "Present" }}
{{end}}
{{with .location}}
<span class="middot-divider"></span>
<span>{{.}}</span>
{{end}}
</div>
{{with .description}}<div class="card-text">{{. | markdownify | emojify}}</div>{{end}}
</div>
</div>
</div>
</div>
{{end}}
{{end}}
</div>
</div>
And here is the widget_page.html:
{{/* Notify JS that this is a widget page */}}
<span class="js-widget-page d-none"></span>
{{/* Get widget page */}}
{{ $page := "" }}
{{ if .IsHome }}
{{ $page = "/home" }}
{{ else }}
{{ $page = .File.Path }}
{{ end }}
{{ $headless_bundle := site.GetPage $page }}
{{/* Check homepage exists */}}
{{ if not $headless_bundle }}
{{ errorf "Homepage not found or duplicate homepages detected for a localization! Add the `home/` folder (especially `/home/index.md`) to each language's content folder. For example, your site should have a `content/home/` folder containing `index.md` and your homepage sections, or for multi-language sites, `content/en/home/` and `content/zh/home/` etc. Refer to the 'Build Your Homepage' and 'Language' documentation at https://sourcethemes.com/academic/docs/ and the example homepage at https://github.com/gcushen/hugo-academic/tree/master/exampleSite/content/home/index.md ." }}
{{ end }}
{{/* Load page sections */}}
{{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
{{/* Begin widget styling */}}
{{ $bg := $st.Params.design.background }}
{{ $style := "" }}
{{ if $bg.color }}
{{ $style = printf "background-color: %s;" ($bg.color | default "transparent") }}
{{ end }}
{{ if and $bg.gradient_start $bg.gradient_end }}
{{ $style = printf "%sbackground-image: linear-gradient(%s, %s);" $style $bg.gradient_start $bg.gradient_end }}
{{ end }}
{{ if $bg.image }}
{{ $darken := "" }}
{{ if $bg.image_darken }}
{{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
{{ end }}
{{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
{{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "img/%s" $bg.image | absURL) }}
{{ with $bg.image_size }}
{{/* Allow sizes: actual, cover, and contain. */}}
{{ $style = printf "%sbackground-size: %s;" $style (replace . "actual" "auto") }}
{{ end }}
{{ with $bg.image_position }}
{{/* Allow valid CSS positions including left, center, and right. */}}
{{ $style = printf "%sbackground-position: %s;" $style . }}
{{ end }}
{{ end }}
{{ with $st.Params.design.spacing.padding }}
{{ $style_pad := printf "padding: %s;" (delimit . " ") }}
{{ $style = print $style $style_pad }}
{{ end }}
{{ with $st.Params.advanced.css_style }}
{{ $style = print $style . }}
{{ end }}
{{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
{{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}
{{ $widget := or $st.Params.widget "blank" }}
{{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
{{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}
{{ $widget_path := printf "widgets/%s.html" $widget }}
{{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
{{ $css_classes := $st.Params.advanced.css_class | default "" }}
{{ $extra_attributes := "" }}
{{ $use_container := true }}
{{/* Special case: Slider widget. */}}
{{ if in (slice "slider") $widget }}
{{ $css_classes = print $css_classes " carousel slide" }}
{{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (string $st.Params.interval | default "5000") }}
{{ $use_container = false }}
{{ end }}
<section id="{{$hash_id}}" class="home-section {{printf "wg-%s" (replace $widget "_" "-")}} {{if $bg.text_color_light}}dark{{end}} {{if $bg.image}} bg-image{{if ($bg.image_parallax | default true) }} parallax{{end}}{{end}} {{with $css_classes}}{{.}}{{end}}" {{with $style}}style="{{. | safeCSS}}"{{end}} {{print $extra_attributes | safeHTMLAttr}}>
{{if $use_container}}<div class="container">{{end}}
{{ partial $widget_path $widget_args }}
{{if $use_container}}</div>{{end}}
</section>
{{ end }}
Any help would be greatly appreciated!
Alex