当前主题DoIt问题修改
Contents
Problem
Error: unable to cast []string{"胡兵"} of type []string to string.
Cause
ox-hugo exports the author frontmatter as a list (e.g., ["Name"]), but the DoIt theme templates expect a single string.
Solution
Modified the theme templates to check if author is a list (slice) and extract the first element if so.
Modified Files
themes/DoIt/layouts/_partials/head/seo.htmlthemes/DoIt/layouts/_partials/meta/author.htmlthemes/DoIt/layouts/_partials/rss/item.html
Code Change
Added the following logic to normalize the author variable:
{{- $authorParam := .Params.author -}}
{{- if reflect.IsSlice $authorParam -}}
{{- if gt (len $authorParam) 0 -}}
{{- $authorParam = index $authorParam 0 -}}
{{- else -}}
{{- $authorParam = nil -}}
{{- end -}}
{{- end -}}
{{- /* Use $authorParam instead of .Params.author */ -}}
Note on item.html
In item.html, I also had to fix a syntax error in the CDATA section by using backticks to avoid “unterminated quoted string” errors:
{{- `<![CDATA[` | safeHTML -}}
...
{{- `]]>` | safeHTML -}}
文若可采,幸赐清茗一盏,以助笔耕不辍