Ice-Hazymoon / hugo-theme-luna

A simple, performance-first, SEO-friendly Hugo theme / 一个轻量,快速,SEO 友好的 Hugo 主题
https://hugo-theme-luna.imiku.me
GNU General Public License v3.0
288 stars 40 forks source link

搜索页构建失败 #98

Closed realth000 closed 1 year ago

realth000 commented 1 year ago

现象

执行hugo serve时报错,hugo build也一样:

ERROR render of "page" failed: "/home/th0/Programming/github_page/themes/hugo-theme-luna/layouts/_default/search.json:10:28": execute of template failed: template: _default/search.json:10:28: executing "_default/search.json" at <append $data>: error calling append: cannot append slice of []string to slice of string Built in 1387 ms Error: error building site: render: failed to render pages: render of "page" failed: "/home/th0/Programming/github_page/themes/hugo-theme-luna/layouts/_default/search.json:10:28": execute of template failed: template: _default/search.json:10:28: executing "_default/search.json" at <append $data>: error calling append: cannot append slice of []string to slice of string

环境

起因是这样,前段时间突然本来能用的博客突然构建报错了,和 #46 的现象一模一样,之后执行npm install --production依然不好用,今天又重新执行了一次,变成了这个错误。

想绕过去的话只需要删除下面这句话,虽然会导致搜索页不可用:

diff --git a/layouts/_default/search.json b/layouts/_default/search.json
index 86b2bc3..9a10e14 100644
--- a/layouts/_default/search.json
+++ b/layouts/_default/search.json
@@ -7,7 +7,6 @@
 {{- range $filtered -}}
     {{- $data := slice (slice .Title (.Date.Format "2006年01月01日") .RelPermalink (replaceRE "( )+?|\r
?\n" " " (replaceRE "```(.|\n)+?```|{{.+?}}(.|\r?\n?)+?{{.+?}}|{{.+?}}|`(.+?)`" " " .RawContent | markdo
wnify | plainify)) ) -}}

-    {{- $result = $result | append $data -}}
 {{- end -}}

但是这样搜索页就用不了了。

ninthday commented 1 year ago

我也出現同樣的問題,謝謝提示。 Hugo v.0.114.0 開始發生的,有人回報了這個狀況,等待作者後續修正了。目前使用的版本是 v.0.117.0 還沒修正。 https://github.com/gohugoio/hugo/issues/11131#issuecomment-1598079671

測試將原本 $data 部分直接取代至 append 後面,可以維持 Search 功能也不會報錯。

{{- $result = $result | append $data -}}

改為

{{- $result = $result | append slice (slice .Title (.Date.Format "2006年01月01日") .RelPermalink (replaceRE "( )+?|\r?\n" " " (replaceRE "```(.|\n)+?```|{{.+?}}(.|\r?\n?)+?{{.+?}}|{{.+?}}|`(.+?)`" " " .RawContent | markdownify | plainify)) ) -}}

OS: Ubuntu 22.04.3 Hugo: v0.117.0+extended

realth000 commented 1 year ago

感谢,已经可以用了。 原来是hugo的问题(

Ice-Hazymoon commented 1 year ago

我也出現同樣的問題,謝謝提示。 Hugo v.0.114.0 開始發生的,有人回報了這個狀況,等待作者後續修正了。目前使用的版本是 v.0.117.0 還沒修正。 https://github.com/gohugoio/hugo/issues/11131#issuecomment-1598079671

測試將原本 $data 部分直接取代至 append 後面,可以維持 Search 功能也不會報錯。

{{- $result = $result | append $data -}}

改為

{{- $result = $result | append slice (slice .Title (.Date.Format "2006年01月01日") .RelPermalink (replaceRE "( )+?|\r?\n" " " (replaceRE "```(.|\n)+?```|{{.+?}}(.|\r?\n?)+?{{.+?}}|{{.+?}}|`(.+?)`" " " .RawContent | markdownify | plainify)) ) -}}

OS: Ubuntu 22.04.3 Hugo: v0.117.0+extended

感谢建议,能麻烦提一个 PR 来修复这个错误吗

ninthday commented 1 year ago

感谢建议,能麻烦提一个 PR 来修复这个错误吗

沒問題,我晚點推一個版本 ;)