github - How can I let Hugo detect theme?
问题描述
I am trying out a Hugo theme and what happened was when I used the command hugo server
, I see the following error message.
Building sites … WARN 2020/07/20 14:33:07 Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url
ERROR 2020/07/20 14:33:07 render of "taxonomy" failed: "D:\Hugo\bin\my_conf\themes\devfest-theme-hugo\layouts\_default\baseof.html:7:3": execute of template failed: template: taxonomy/list.html:7:3: executing "taxonomy/list.html" at <readFile "static/icons.svg">: error calling readFile: file "static\\icons.svg" does not exist
ERROR 2020/07/20 14:33:07 render of "home" failed: "D:\Hugo\bin\my_conf\themes\devfest-theme-hugo\layouts\_default\baseof.html:7:3": execute of template failed: template: index.html:7:3: executing "index.html" at <readFile "static/icons.svg">: error calling readFile: file "static\\icons.svg" does not exist
Built in 100 ms
Error: Error building site: failed to render pages: render of "taxonomy" failed: "D:\Hugo\bin\my_conf\themes\devfest-theme-hugo\layouts\_default\baseof.html:7:3": execute of template failed: template: taxonomy/list.html:7:3: executing "taxonomy/list.html" at <readFile "static/icons.svg">: error calling readFile: file "static\\icons.svg" does not exist
It seems saying that I misplaced some of the template files. I wonder if I have installed the theme correctly, or something I misunderstood?
What I have Done
- Installed
hugo
and confirmed it is installed. - Created a new site called
my-conf
(Just trying out) and thethemes
directory. - I've cloned the repository into my
themes
directory. I am using GitHub Desktop on Windows. - Added the theme information using
theme = "devfest-theme-hugo"
. - Used the command
hugo server
.
解决方案
Ideally, you would add the themes as a submodule, as in the documentation, and the theme page itself:
hugo new site my-conf
cd my-conf
mkdir themes
git submodule add https://github.com/GDGToulouse/devfest-theme-hugo.git themes/devfest-theme-hugo
And add it to your configuration (which you seem to have done):
echo 'theme = "ananke"' >> config.toml
Then, regarding readFile
:
To use the
readFile
function in your templates, make sure the path is relative to your Hugo project’s root directory:
{{ readFile "/content/templates/local-file-templates" }}
In the template: layouts/_default/baseof.html
seems to have the right path.
Yet, looking at the history of GDGToulouse/devfest-theme-hugo/layouts/_default/baseof.html
, I see it has changed during a commit "WIP 2020".
The version before that commit included:
{{ readFile "themes/devfest-theme-hugo/static/icons.svg" | safeHTML }}
Which, from the discussion, seems to work better!
推荐阅读
- excel - 运行时错误“1004”:对象“_Global”的方法“范围”在具有 LastRow 和 Workbook_Sheetchange 的 VBA 代码中失败
- three.js - Three.js:为立方体的每个面添加不同的颜色
- sql - 在 SQL Server 2017 中加入两个表时,查询未返回正确的计数
- javascript - 不带new关键字调用构造函数的两种情况比较
- java - 通过数据流将数据写入文件时如何将PCollection数据的编码更改为ASCII
- postgresql - PostgreSQL 11 和 Oracle 外部数据包装器
- arrays - 如何读取表中的 JSON 值对
- linux - 搜索和替换服务器中的所有文件
- ios - 没有断点就无法播放音频
- javascript - 我应该调用多少次 firebase.analytics()?