如何解决安装后尝试在 Hugo 中创建第一个网站帖子时出现“解组失败”
我按照 Hugo 的快速入门指南 (https://gohugo.io/getting-started/quick-start/) 中的说明进行操作,但在我尝试创建帖子时不断收到此错误消息:
unmarshal failed: Near line 1 (last key parsed 'theme'): expected value but found '\\' instead
我在下面发布了一些代码行。错误消息出现在底部。谁能帮忙指出我做错了什么?
C:\Users\Scott\quickstart\MyHugoBlog\themes>git init
Initialized empty Git repository in C:/Users/Scott/quickstart/MyHugoBlog/themes/.git/
C:\Users\Scott\quickstart\MyHugoBlog\themes>git submodule add https://github.com/dashdashzako/paperback.git
Cloning into 'C:/Users/Scott/quickstart/MyHugoBlog/themes/paperback'...
remote: Enumerating objects: 16,done.
remote: Counting objects: 100% (16/16),done.
remote: Compressing objects: 100% (15/15),done.
remote: Total 194 (delta 3),reused 9 (delta 1),pack-reused 178 eceiving objects: 53% (103/194)
Receiving objects: 100% (194/194),466.30 KiB | 5.62 MiB/s,done.
Resolving deltas: 100% (93/93),done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory
C:\Users\Scott\quickstart\MyHugoBlog\themes>echo theme = \"paperback\" >> config.toml
C:\Users\Scott\quickstart\MyHugoBlog\themes>hugo new posts/my-first-post.md
Error: "C:\Users\Scott\quickstart\MyHugoBlog\themes\config.toml:1:1": unmarshal failed: Near line 1 (last key parsed 'theme'): expected value but found '\\' instead
解决方法
您似乎正在遵循适用于 Windows 上的类 Unix 系统的说明。此命令没有执行您想要的操作:
echo theme = \"paperback\" >> config.toml
例如在 Linux 上使用 Bash,这个附加
theme = "paperback"
添加到您的 config.toml
文件,必要时创建它。这就是 Hugo 希望在文件中找到的内容。
但是,在 Windows 上使用 cmd.exe
我得到了反斜杠:
theme = \"paperback\"
使用 PowerShell,我得到了更奇怪的东西:
theme
=
\paperback\
对我来说,这些都不是有效的 TOML,并且都包含错误消息中引用的无关紧要的反斜杠。我建议您使用您喜欢的文本编辑器简单地编辑 config.toml
并添加预期的
theme = "paperback"
手动排线。