更新后无法提供 hugo 主题;获得 "error calling partial:execute of template failed: error calling delimit: can't iterate over <nil>"
Unable to serve hugo theme after update; getting "error calling partial:execute of template failed: error calling delimit: can't iterate over <nil>"
我正在尝试更新使用 hugo-coder
主题的博客。我已经尝试更新我添加的子模块,post 当我 运行 hugo server
命令时升级,我得到以下异常:
Change of config file detected, rebuilding site.
2021-03-15 22:01:46.390 +0530
ERROR 2021/03/15 22:01:46 render of "taxonomy" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:11:9: executing "_default/single.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
Rebuilt in 65 ms
config.toml
文件中 params.csp
的条目如下:
[params.csp]
scriptsrc = ["'self'",
"'unsafe-inline'",
"https://platform.twitter.com",
"https://cdn.syndication.twimg.com",
"*.amazon-adsystem.com",
"https://www.google-analytics.com",
"cse.google.com",
"https://www.google.com",
"https://pagead2.googlesyndication.com",
"https://adservice.google.com",
"https://www.googletagservices.com",
"jsfiddle.net",
"www.instagram.com",
"disqus.com",
"disquscdn.com",
"*.disqus.com",
"*.disquscdn.com"]
csp部分内容如下:
{{ printf `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests; block-all-mixed-content; default-src 'self'; child-src %s; font-src %s; form-action %s; frame-src %s; img-src %s; object-src %s; style-src %s; script-src %s; prefetch-src %s;">` (delimit .Site.Params.csp.childsrc " ") (delimit .Site.Params.csp.fontsrc " ") (delimit .Site.Params.csp.formaction " ") (delimit .Site.Params.csp.framesrc " ") (delimit .Site.Params.csp.imgsrc " ") (delimit .Site.Params.csp.objectsrc " ") (delimit .Site.Params.csp.stylesrc " ") (delimit .Site.Params.csp.scriptsrc " ") (delimit .Site.Params.csp.prefetchsrc " ") | safeHTML }}
有人可以帮我解决这里的问题吗?如果我删除 CSP 部分,则会提供该网站。
好的,原来我的 config.toml
文件中缺少相关的安全策略。我参考了默认 config.toml 文件 here
配置文件应该看起来像这样:
# If you want to implement a Content-Security-Policy, add this section
[params.csp]
childsrc = ["'self'"]
fontsrc = ["'self'", "https://fonts.gstatic.com", "https://cdn.jsdelivr.net/"]
formaction = ["'self'"]
framesrc = ["'self'"]
imgsrc = ["'self'"]
objectsrc = ["'none'"]
stylesrc = [
"'self'",
"'unsafe-inline'",
"https://fonts.googleapis.com/",
"https://cdn.jsdelivr.net/"
]
scriptsrc = ["'self'", "'unsafe-inline'", "https://www.google-analytics.com"]
prefetchsrc = ["'self'"]
更新我的 config.toml
文件以包含其他安全策略后,网站现在可以加载。
我正在尝试更新使用 hugo-coder
主题的博客。我已经尝试更新我添加的子模块,post 当我 运行 hugo server
命令时升级,我得到以下异常:
Change of config file detected, rebuilding site.
2021-03-15 22:01:46.390 +0530
ERROR 2021/03/15 22:01:46 render of "taxonomy" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 render of "term" failed: execute of template failed: template: _default/list.html:11:9: executing "_default/list.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
ERROR 2021/03/15 22:01:46 failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:11:9: executing "_default/single.html" at <partial "csp.html" .>: error calling partial: "/Users/ishabbi/PlayGround/rookieBlog/themes/hugo-coder/layouts/partials/csp.html:1:269": execute of template failed: template: partials/csp.html:1:269: executing "partials/csp.html" at <delimit .Site.Params.csp.childsrc " ">: error calling delimit: can't iterate over <nil>
Rebuilt in 65 ms
config.toml
文件中 params.csp
的条目如下:
[params.csp]
scriptsrc = ["'self'",
"'unsafe-inline'",
"https://platform.twitter.com",
"https://cdn.syndication.twimg.com",
"*.amazon-adsystem.com",
"https://www.google-analytics.com",
"cse.google.com",
"https://www.google.com",
"https://pagead2.googlesyndication.com",
"https://adservice.google.com",
"https://www.googletagservices.com",
"jsfiddle.net",
"www.instagram.com",
"disqus.com",
"disquscdn.com",
"*.disqus.com",
"*.disquscdn.com"]
csp部分内容如下:
{{ printf `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests; block-all-mixed-content; default-src 'self'; child-src %s; font-src %s; form-action %s; frame-src %s; img-src %s; object-src %s; style-src %s; script-src %s; prefetch-src %s;">` (delimit .Site.Params.csp.childsrc " ") (delimit .Site.Params.csp.fontsrc " ") (delimit .Site.Params.csp.formaction " ") (delimit .Site.Params.csp.framesrc " ") (delimit .Site.Params.csp.imgsrc " ") (delimit .Site.Params.csp.objectsrc " ") (delimit .Site.Params.csp.stylesrc " ") (delimit .Site.Params.csp.scriptsrc " ") (delimit .Site.Params.csp.prefetchsrc " ") | safeHTML }}
有人可以帮我解决这里的问题吗?如果我删除 CSP 部分,则会提供该网站。
好的,原来我的 config.toml
文件中缺少相关的安全策略。我参考了默认 config.toml 文件 here
配置文件应该看起来像这样:
# If you want to implement a Content-Security-Policy, add this section
[params.csp]
childsrc = ["'self'"]
fontsrc = ["'self'", "https://fonts.gstatic.com", "https://cdn.jsdelivr.net/"]
formaction = ["'self'"]
framesrc = ["'self'"]
imgsrc = ["'self'"]
objectsrc = ["'none'"]
stylesrc = [
"'self'",
"'unsafe-inline'",
"https://fonts.googleapis.com/",
"https://cdn.jsdelivr.net/"
]
scriptsrc = ["'self'", "'unsafe-inline'", "https://www.google-analytics.com"]
prefetchsrc = ["'self'"]
更新我的 config.toml
文件以包含其他安全策略后,网站现在可以加载。