首页 > 解决方案 > 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

  1. Installed hugo and confirmed it is installed.
  2. Created a new site called my-conf (Just trying out) and the themes directory.
  3. I've cloned the repository into my themes directory. I am using GitHub Desktop on Windows.
  4. Added the theme information using theme = "devfest-theme-hugo".
  5. Used the command hugo server.

标签: githubhugo

解决方案


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!


推荐阅读