【问题标题】:How can I let Hugo detect theme?如何让 Hugo 检测主题?
【发布时间】:2020-11-09 07:50:01
【问题描述】:

我正在尝试一个 Hugo 主题,当我使用命令 hugo server 时,我看到了以下错误消息。

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

似乎是说我放错了一些模板文件。我想知道我是否正确安装了主题,还是我误解了什么?

我做了什么

  1. 已安装hugo 并确认已安装。
  2. 创建了一个名为 my-conf 的新站点(刚刚试用)和 themes 目录。
  3. 我已将存储库克隆到我的themes 目录中。我在 Windows 上使用 GitHub Desktop。
  4. 添加了使用theme = "devfest-theme-hugo"的主题信息。
  5. 使用命令hugo server

【问题讨论】:

    标签: github hugo


    【解决方案1】:

    理想情况下,您可以将主题添加为子模块as in the documentationtheme 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
    

    并将其添加到您的配置中(您似乎已经这样做了):

    echo 'theme = "ananke"' >> config.toml
    

    那么,regarding readFile:

    要在模板中使用 readFile 函数,请确保路径是相对于 Hugo 项目的根目录的:

    {{ readFile "/content/templates/local-file-templates" }}
    

    在模板中:layouts/_default/baseof.html 似乎有正确的路径。

    然而,看看GDGToulouse/devfest-theme-hugo/layouts/_default/baseof.html 的历史,我发现它已经改变了during a commit "WIP 2020"

    version before that commit 包括:

    {{ readFile "themes/devfest-theme-hugo/static/icons.svg" | safeHTML }}
    

    哪个,来自the discussion,似乎效果更好!

    【讨论】:

    • 谢谢。所以克隆和添加子模块不一样吧?
    • @SHY.John 否:通过在父存储库中克隆,父存储库不会记住您的嵌套存储库(主题)来自 哪里
    • 我正在使用 Github Desktop,你知道我是否可以从那里添加子模块吗?
    • @SHY.John 从我在github.com/desktop/desktop/issues/708 中可以看到的内容来看,这似乎并不完全得到支持。 git submodule add,在命令行中,仍然是最安全的选择。
    • @SHY.John 否:stackoverflow.com/a/54679083/6309。为此,您需要适用于 Windows 的 Git:stackoverflow.com/a/54104048/6309
    猜你喜欢
    • 2016-12-13
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多