I have been trying to implement glossary modals and was attempting to handle the recursive nature.
However, I am facing the below error:
$ hugo server -D --disableFastRender --enableGitInfo --gc --ignoreCache -N --noHTTPCache
ERROR render of "page" failed: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\themes\PaperMod\layouts\_default\baseof.html:9:8": execute of template failed: template: _default/single.html:9:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: execute of template failed: template: partials/templates/schema_json.html:73:20: executing "partials/templates/schema_json.html" at <.Content>: error calling Content: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\content\blogs\Overcoming-(discord)-API-Rate-Limits-With-Redis-Cache.md:17:17": failed to render shortcode "glossary": failed to process shortcode: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\layouts\shortcodes\glossary.html:51:48": execute of template failed: template: shortcodes/glossary.html:51:48: executing "shortcodes/glossary.html" at <markdownify>: error calling markdownify: runtime error: slice bounds out of range [:40] with capacity 0
ERROR render of "page" failed: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\themes\PaperMod\layouts\_default\baseof.html:9:8": execute of template failed: template: _default/single.html:9:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: execute of template failed: template: partials/templates/schema_json.html:73:20: executing "partials/templates/schema_json.html" at <.Content>: error calling Content: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\content\blogs\What_are_HTTP_and_HTTPS_Protocols.md:19:144": failed to render shortcode "glossary": failed to process shortcode: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\layouts\shortcodes\glossary.html:51:48": execute of template failed: template: shortcodes/glossary.html:51:48: executing "shortcodes/glossary.html" at <markdownify>: error calling markdownify: runtime error: slice bounds out of range [:71] with capacity 0
Built in 457 ms
Error: error building site: render: failed to render pages: render of "page" failed: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\themes\PaperMod\layouts\_default\baseof.html:9:8": execute of template failed: template: _default/single.html:9:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: execute of template failed: template: partials/templates/schema_json.html:73:20: executing "partials/templates/schema_json.html" at <.Content>: error calling Content: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\content\blogs\What_Are_Browser_HTTP_Cookies.md:17:47": failed to render shortcode "glossary": failed to process shortcode: "F:\sandy-personal\ProgStudy\projects\ADeveloperHasNoName\layouts\shortcodes\glossary.html:51:48": execute of template failed: template: shortcodes/glossary.html:51:48: executing "shortcodes/glossary.html" at <markdownify>: error calling markdownify: runtime error: slice bounds out of range [:71] with capacity 0
Appears the error is occuring in the glossary.md
shortcut:
{{- $glossary := site.GetPage "glossary.md" -}}
{{- $term := .Get "term" -}}
{{- $displayTerm := .Get "displayTerm" | default $term -}}
{{- $ancestorTerms := .Get "ancestorTerms" | default "" -}}
{{- $term := $term | lower -}}
{{- $definition := "" -}}
{{- /*
`ancestorTerms` is a string of previously visited terms delimited by `{}`.
If the current term is in the ancestorTerms, then the term is a circular reference
and the displayTerm is returned to prevent infinite recursion
*/ -}}
{{- if in $ancestorTerms (printf `{%s}` $term) -}}
{{- return $displayTerm -}}
{{- end -}}
{{- range $key, $value := $glossary.Params.glossary -}}
{{- if eq (lower $key) $term -}}
{{- $definition = $value -}}
{{- end -}}
{{- end -}}
{{- if $definition -}}
{{- /*
The glossary shortcode is of the pattern `{{< glossary term="term" displayTerm="displayTerm" ancestorTerms="ancestorTerms" >}}`
ancestorTerms is used to prevent infinite recursion in the glossary shortcode where terms are delimited by `{}`
Below matches the value of the `ancestorTerms` attribute of the `glossary` shortcode and appends the current term to the ancestorTerms.
*/ -}}
{{- $shortcodePattern := `\{\{[ ]*<[ ]*glossary[ ]+term="(?<d_term>[^"]+)"(?:[ ]+displayTerm="(?<d_displayTerm>[^"]+)")?(?:[ ]+ancestorTerms="(?<d_ancestorTerms>[^"]+)")?[ ]*>[ ]*\}\}` -}}
{{- $updatedDefinition := replaceRE $shortcodePattern (printf `{{< glossary term="$d_term" displayTerm="$d_displayTerm" ancestorTerms="%s{%s}" >}}` $ancestorTerms $term) $definition -}}
{{- if not $updatedDefinition -}}
{{- return $displayTerm -}}
{{- end -}}
{{- /* Debugging: Print updated definition */ -}}
{{- warnf "Term: %s, AncestorTerms: %s, Definition: %s" $term $ancestorTerms $definition -}}
{{- warnf "." -}}
{{- warnf "." -}}
{{- /* Prevents multiple glossary terms on the same page from sharing the same modal ID */ -}}
{{- $unique_id := delimit (shuffle (seq 1 15)) "" -}}
<span class="glossary-container" onclick="openModal('{{- $term }}', '{{- $unique_id }}')">
<span class="glossary-term"> {{- $displayTerm -}} </span>
<span id="modal-{{- $term }}-{{- $unique_id }}" class="glossary-modal">
<span class="modal-content">
<span> {{- $updatedDefinition | markdownify -}} </span>
<span class="modal-close" onclick="closeModal('{{- $term }}', '{{- $unique_id }}')">×</span>
</span>
</span>
</span>
{{- else -}}
{{- $displayTerm -}}
{{- end -}}
I do not know how to debug this. Please help me.
If it is of any relevance, I am using papermod theme.
the source repo: GitHub - sandeshShahapur/ADeveloperHasNoName
Here is my env
$ hugo env
hugo v0.135.0+extended windows/386 BuildDate=unknown
GOOS="windows"
GOARCH="386"
GOVERSION="go1.23.2"
github.com/sass/libsass="3.6.6"
github.com/webmproject/libwebp="v1.3.2"