【问题标题】:Hugo fails to build site, saying it is unable to find a themeHugo建站失败,说找不到主题
【发布时间】:2017-03-19 20:56:15
【问题描述】:

我正在尝试在 Gitlab 上部署一个 hugo 网站,但它返回以下错误:

WARN: 2016/11/04 14:57:24 hugo.go:547: Unable to find static directory for theme strange-case in /builds/joaoeira/hugo/themes/strange-case/static

主题“strange-case”位于主题文件夹内,并且它有一个静态文件夹,这就是为什么我发现这个问题令人费解。在这里,我包括了我部署网站所采取的步骤(它说 github,因为那是我的第一次尝试):

git submodule add https://github.com/ExchangeRate-API/strange-case.git
git remote add origin https://github.com/joaoeira/joaoeira.github.io.git
hugo -t strange-case
git add .
git commit -m "first commit"
git push origin master

hugo 给我的最后一条信息:

=============================================================
Your rendered home page is blank: /index.html is zero-length
* Did you specify a theme on the command-line or in your
"config.toml" file? (Current theme: "strange-case")
* For more debugging information, run "hugo -v"
=============================================================

有什么猜测吗?

我的 config.toml 文件:

baseurl = "https://joaoeira.gitlab.io"
title = "Lettuce be Cereal"
author = "João Eira"
copyright = "Your Copyright"
canonifyurls = true
paginate = 5
PygmentsCodeFences = false

googleAnalytics = ""

contentdir = "content/post"
layoutdir = "layouts"
publishdir = "public"
theme = "strange-case"

[params]
    colorScheme = "scheme-darkbrown"
    DateFormat = "2 Jan 2006"
    description ="João Eira is a Master's student in Economics at Universidade de Coimbra."
    sidebarDescription = "João Eira's personal blog"
    sidebarFreeText =  "\"Shared fictions are the necessary condition of social coordination.\""
    piwikSiteID = ""
    piwikURL = ""


[[menu.main]]
    name = "About"
    url = "http://joaoeira.com"

[[menu.main]]
    name = "Twitter"
    url = "http://twitter.com/joaoeira"

我的 .gitlab.ci.yml 文件。注意指定主题和所有内容的“hugo -t奇异案例-v”:

image: alpine:3.4

before_script:
  - apk update && apk add openssl
  - wget https://github.com/spf13/hugo/releases/download/v0.16/hugo_0.16_linux-64bit.tgz
  - echo "37ee91ab3469afbf7602a091d466dfa5  hugo_0.16_linux-64bit.tgz" | md5sum -c
  - tar xf hugo_0.16_linux-64bit.tgz && cp ./hugo /usr/bin
  - hugo version

test:
  script:
  - hugo
  except:
  - master

pages:
  script:
  - hugo -t strange-case -v
  artifacts:
    paths:
    - public
  only:
  - master

【问题讨论】:

  • 子模块在我的情况下引起了问题。通过从主题的根文件夹中删除 .git 文件夹,将子模块转换为普通(非 git)文件夹。它能解决你的问题吗?
  • 从那以后你设法解决了这个问题吗?

标签: gitlab hugo


【解决方案1】:

可能的解决方案

(!) 确保在 hugo 的 config.toml 中更新您的 baseUrl

在我的情况下,hugo 在本地渲染得很好,但在我部署到 gitlab 页面时却无法正常工作。

我是如何得到错误的

最初,根据 Hugo 快速入门,我将主题 (ananke) 安装在正确的位置 (repo/thems/ananke)。但是,当我的站点没有在 gitlab 页面上呈现时,我尝试将模块移动到 publicc 中,因为我担心它无法用于部署。那时我遇到了与上面的 OP 相同的错误。

但是,当设置我的baseUrl 以匹配 gitlab 页面提供的 url(并将我的它们移回顶级 themes 目录)时,一切正常。 :)

免责声明

YMMV,但最后baseUrl 是我所缺少的。我从 Hugo 快速入门和 hugo 部署到 gitlab 教程中学到的所有其他内容。

【讨论】:

    【解决方案2】:

    在我的情况下,问题在于子模块。我必须在 .gitmodules 中使用相对 url 提及子模块。在 .gitlab-ci.yml 中,变量 GIT_SUBMODULE_STRATEGY 必须设置为 recursive

    为此,我在命名空间中分叉了主题并使用了下一个配置。

    .gitmodules

    [submodule "themes/hugo-universal-theme"]
    path = themes/hugo-universal-theme
    url = ../hugo-universal-theme.git
    

    .gitlab-ci.yml

    # All available Hugo versions are listed here: https://gitlab.com/pages/hugo/container_registry
    image: registry.gitlab.com/pages/hugo:latest
    
    variables:
      GIT_SUBMODULE_STRATEGY: recursive
    
    pages:
      script:
      - hugo
      artifacts:
        paths:
        - public
      only:
      - master
    

    【讨论】:

    • 如果我理解正确,除非您真的想保持与原始主题的差异,否则您不需要分叉主题。同时,这在您的本地测试中是如何工作的?您是否必须在您的计算机上的(网站)存储库以及您的 gitlab 帐户旁边放置分叉主题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多