Update link render hook to support glossary links

This commit is contained in:
Joe Mooring authored and GitHub committed 2025-01-19 16:40:42 -08:00
1 parent 53eadb430f
commit cd95f0f34e
5 files changed
+354 -15

No files matched your search

+17 -13
View File
@@ -21,22 +21,26 @@ fragment, it points to an entry on the glossary page.
{{- $termActual := "" }}
{{- $termSingular := inflect.Singularize $termGiven }}
{{- if site.GetPage (urls.JoinPath $basePath $termGiven) }}
{{- $termActual = $termGiven }}
{{- else if site.GetPage (urls.JoinPath $basePath $termSingular) }}
{{- $termActual = $termSingular}}
{{- else }}
{{- errorf "The glossary link (%s) shortcode was unable to find a defintion for either the singular or plural form of the term %q: see %s" $.Name $termGiven $.Position }}
{{- end }}
{{- with $gp :=site.GetPage $basePath }}
{{- if $termActual }}
{{- with site.GetPage $basePath }}
{{- $href := fmt.Printf "%s#%s" .RelPermalink (anchorize $termActual) }}
[{{ $termGiven }}]({{ $href }}){{/* Do not indent. */}}
{{- /* Validate the given term using its singular and plural forms. */}}
{{- if site.GetPage (urls.JoinPath $basePath $termGiven) }}
{{- $termActual = $termGiven }}
{{- else if site.GetPage (urls.JoinPath $basePath $termSingular) }}
{{- $termActual = $termSingular}}
{{- else }}
{{- errorf "The glossary link (%s) shortcode was unable to find %s: see %s" $.Name $basePath $.Position }}
{{- errorf "The glossary link (%s) shortcode was unable to find a defintion for either the singular or plural form of the term %q: see %s" $.Name $termGiven $.Position }}
{{- end }}
{{- /* Render the link. */}}
{{- if $termActual }}
{{- $href := fmt.Printf "%s#%s" $gp.RelPermalink (anchorize $termActual) }}
[{{ $termGiven }}]({{ $href }}){{/* Do not indent. */}}
{{- end }}
{{- else }}
{{- errorf "The glossary link (%s) shortcode was unable to find %s: see %s" $.Name $basePath $.Position }}
{{- end }}
{{- else }}
{{- errorf "The glossary link (%s) shortcode requires one positional parameter: see %s" $.Name $.Position }}
{{- end }}
{{- end -}}