GitLab 页面

我们将使用 GitLab CI 运行器自动发布站点(如果您使用 GitLab.com,此 CI 运行器已包含在您的存储库中)。

🔗存储库设置

您的存储库需要设置为用户或组网站。这意味着存储库的名称必须采用正确的格式。

例如,假设用户名是john,您必须创建一个名为 的项目john.gitlab.io您的项目 URL 将为https://gitlab.com/john/john.gitlab.io. 为您的项目启用 GitLab Pages 后,您的网站将发布在https://john.gitlab.io.

在您的组下websites,您创建了一个名为 的项目websites.gitlab.io您项目的 URL 将为https://gitlab.com/websites/websites.gitlab.io. 为您的项目启用 GitLab Pages 后,您的网站将发布在https://websites.gitlab.io.

本指南假定您的 Zola 项目位于存储库的根目录中。

🔗确保 CI 运行者可以访问你的主题

根据您添加主题的方式,您的存储库可能不包含它。确保添加主题的最佳方法是使用子模块。执行此操作时,请确保您使用的是httpsURL 的版本。

$ git submodule add {THEME_URL} themes/{THEME_NAME}

例如,这可能看起来像:

$ git submodule add https://github.com/getzola/hyde.git themes/hyde

🔗设置 GitLab CI/CD 运行器

第二步是告诉 GitLab 持续集成运行器如何创建 GitLab 页面。

为此,请.gitlab-ci.yml在存储库的根目录中创建一个名为的文件。

image: alpine:latest
variables:
  # This variable will ensure that the CI runner pulls in your theme from the submodule
  GIT_SUBMODULE_STRATEGY: recursive

pages:
  script:
    # Install the zola package from the alpine community repositories
    - apk add --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ zola
    # Execute zola build
    - zola build

  artifacts:
    paths:
      # Path of our artifacts
      - public

  # This config will only publish changes that are pushed on the master branch
  only:
    - master

推送这个新文件然后...... Tada!你完成了!如果您导航到settings > pages,您应该能够看到类似这样的内容:

恭喜!您的页面在以下位置提供: https:
//john.gitlab.io

有关在 GitLab 页面上托管的过程的更多信息以及使用自定义域等其他信息,请参阅 此 GitLab 博客文章