Some Hugo Troubleshooting Tips

ERROR: 2015/12/27 reflect: call of reflect.Value.Type on zero Value in theme/partials/head.html

Encountered this when I tested hugo-icarus-theme.

Turns out that hugo-icarus-theme includes the internal opengraph.html template, which reads .Site.Taxonomies.series, and if it were not defined in config.toml like so:

[taxonomies]
series = "series"

then trouble ensures.

Now, is there a way to

series = ["Hugo is my life"]
.Site.Taxonomies.series
map[hugo-is-my-life:[{0 }] hugo:[{0 } {0 }]]
$name
Hugo is my life
$name | urlize
hugo-is-my-life;

  • taxonomy.go has a kp() function which uses MakePathSanitized().
  • urlize template function, on the other hand, calls URLize(), which not only calls MakePathSanitized(), but also parsedUri()…

Given map[hugo:[{0 } {0 }] hugo-is-my-life:[{0 }] chinese-中文:[{0 }]]:

  • Hugo is my life

    • hugo-is-my-life
    • /Hugo%20is%20my%20life
    • hugo-is-my-life
  • Chinese 中文

    • {{ $name | urlize }}: chinese-%E4%B8%AD%E6%96%87
    • {{ $name | sanitizeURL }}: /Chinese%20%E4%B8%AD%E6%96%87
    • {{ $name | makePathSanitized }}: chinese-中文

Proposals:

diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
index 87dde32..fade8a5 100644
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -1387,6 +1387,7 @@ func Base64Encode(content interface{}) (string, error) {
 
 func init() {
 	funcMap = template.FuncMap{
+		"makePathSanitized": helpers.MakePathSanitized,
 		"urlize":       helpers.URLize,
 		"sanitizeURL":  helpers.SanitizeURL,
 		"sanitizeurl":  helpers.SanitizeURL,
  1. Add makePathSanitized template function:
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -1387,6 +1387,7 @@ func Base64Encode(content interface{}) (string, error) {
 
 func init() {
 	funcMap = template.FuncMap{
+		"makePathSanitized": helpers.MakePathSanitized,
 		"urlize":       helpers.URLize,
 		"sanitizeURL":  helpers.SanitizeURL,
 		"sanitizeurl":  helpers.SanitizeURL,
  1. Fix the embedded opengraph.html template:

    ```diff diff –git a/tpl/template_embedded.go b/tpl/template_embedded.go index b54f92e..c45ec5c 100644 — a/tpl/template_embedded.go +++ b/tpl/template_embedded.go @@ -164,6 +164,7 @@ func (t *GoHTMLTemplate) EmbedTemplates() { {{ $permalink := .Permalink }} {{ $siteSeries := .Site.Taxonomies.series }}{{ with .Params.series }} {{ range $name := . }}

  2. {{ $name := $name | makePathSanitized }} {{ $series := index $siteSeries $name }} {{ range $page := first 6 $series.Pages }} {{ if ne $page.Permalink $permalink }}{{ end }} ```

  3. Perhaps rename these functions? URLize, sanitizeURL, MakePath, MakePathSanitized, etc. etc. are all just too confusing.

References: