google / docsy-example

An example documentation site using the Docsy Hugo theme
https://docsy.dev
Apache License 2.0
470 stars 685 forks source link

Intermittent: error calling Paginate: cannot convert type page.PagesGroup to Pages #199

Closed jgoerz closed 1 year ago

jgoerz commented 1 year ago

TL;DR Deleting the cache file referenced in the error seems to make the error go away with (I believe) no ill effects.

My info:

$ hugo env
hugo v0.110.0+extended linux/amd64 BuildDate=unknown
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.19.5"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.2.4"

I created the site using hugo new site name-of-site and using hugo as a module. Once complete, I copied minimal content items from the mostly docs repository. Specifically, I used their content/en/_index.md frontmatter that is using the cascade feature.

When I build or try to run this site locally I get the error about every 2 out of 3 times building/running it. The error:

$ hugo serve
Start building sites … 
hugo v0.110.0+extended linux/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "section" failed: "/tmp/hugo_cache/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.6.0/layouts/blog/list.html:11:13": execute of template failed: template: blog/list.html:11:13: executing "main" at <.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 641 ms
$

This looks very close to issue #56, but the referenced error file (below) has the fix from that closed issue)

Below is the file that the error is referring to (I added line numbers for reference):

  1 {{ define "main" }}                                                                                                                                                                                                                                       
  2 {{ if (and .Parent .Parent.IsHome) }}                                                                                                                                                                                                                     
  3 {{ $.Scratch.Set "blog-pages" (where .Site.RegularPages "Section" .Section) }}                                                                                                                                                                            
  4 {{ else }}                                                                                                                                                                                                                                                
  5 {{$.Scratch.Set "blog-pages" .Pages }}                                                                                                                                                                                                                    
  6 {{ end }}                                                                                                                                                                                                                                                 
  7                                                                                                                                                                                                                                                           
  8 <div class="row">                                                                                                                                                                                                                                         
  9   <div class="col-12">                                                                                                                                                                                                                                    
 10     {{- if .Pages -}}                                                                                                                                                                                                                                     
 11     {{ $pag := .Paginate (( $.Scratch.Get "blog-pages").GroupByDate "2006" )}}                                                                                                                                                                            
 12       {{ range $pag.PageGroups }}                                                                                                                                                                                                                         
 13       <h2>{{ T "post_posts_in" }} {{ .Key }}</h2>                                                                                                                                                                                                         
 14       <ul class="list-unstyled mt-4">                                                                                                                                                                                                                     
 15         {{ range .Pages }}                                                                                                                                                                                                                                
 16         <li class="media mb-4">                                                                                                                                                                                                                           
 17           <div class="media-body">                                                                                                                                                                                                                        
 18             <h5 class="mt-0 mb-1"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h5>                                                                                                                                                                     
 19             <p class="mb-2 mb-md-3"><small class="text-muted">{{ .Date.Format ($.Param "time_format_blog") }} {{ T "ui_in"}} {{ .CurrentSection.LinkTitle }}</small></p>                                                                                  
 20             <header class="article-meta">                                                                                                                                                                                                                 
 21               {{ partial "taxonomy_terms_article_wrapper.html" . }}                                                                                                                                                                                       
 22               {{ if (and (not .Params.hide_readingtime) (.Site.Params.ui.readingtime.enable)) }}                                                                                                                                                          
 23                 {{ partial "reading-time.html" . }}                                                                                                                                                                                                       
 24               {{ end }}                                                                                                                                                                                                                                   
 25             </header>                                                                                                                                                                                                                                     
 26             {{ partial "featured-image.html" (dict "p" . "w" 250 "h" 125 "class" "float-left mr-3 pt-1 d-none d-md-block") }}                                                                                                                             
 27             <p class="pt-0 mt-0">{{ .Plain | safeHTML | truncate 250 }}</p>                                                                                                                                                                               
 28             <p class="pt-0"><a href="{{ .RelPermalink }}" aria-label="{{ T "ui_read_more"}} - {{ .LinkTitle }}">{{ T "ui_read_more"}}</a></p>                                                                                                             
 29           </div>                                                                                                                                                                                                                                          
 30         </li>                                                                                                                                                                                                                                             
 31         {{ end }}                                                                                                                                                                                                                                         
 32       </ul>                                                                                                                                                                                                                                               
 33       {{ end }}                                                                                                                                                                                                                                           
 34     {{ end }}                                                                                                                                                                                                                                             
 35   </div>                                                                                                                                                                                                                                                  
 36 </div>                                                                                                                                                                                                                                                    
 37 <div class="row pl-2 pt-2">                                                                                                                                                                                                                               
 38   <div class="col">                                                                                                                                                                                                                                       
 39     {{ if .Pages }}                                                                                                                                                                                                                                       
 40       {{ template "_internal/pagination.html" . }}                                                                                                                                                                                                        
 41     {{ end }}                                                                                                                                                                                                                                             
 42   </div>                                                                                                                                                                                                                                                  
 43 </div>                                                                                                                                                                                                                                                    
 44 {{ end }} 

I tried exploring and doing different things to see if I could isolate the problem. The only thing that seemed to work was to delete the file referenced in the error. After doing that, no more build errors, and it appears to have no effect on the output. :shrug:

jgoerz commented 1 year ago

My apologies. I just realized this is the docsy-example repo and this bug belongs on the docsy repo. I'll file this issue there. Please close.