GitLab 页面

  1. 创建一个名为username.gitlab.io的新存储库,其中 username 是你在 GitLab 上的用户名。如果你已经上传到其他 repo,请重命名该 repo。

    ¥Create a new repository named username.gitlab.io, where username is your username on GitLab. If you have already uploaded to other repo, rename the repo instead.

  2. 通过“设置”>“CI/CD”>“运行器”>“为此项目启用共享运行器”启用共享运行器。

    ¥Enable Shared Runners via Settings > CI/CD > Runners > Enable shared runners for this project.

  3. 将 Hexo 文件夹的文件推送到存储库。默认情况下不会(也不应该)上传 public/ 文件夹,请确保 .gitignore 文件包含 public/ 行。文件夹结构应该与 此 repo 大致相似。

    ¥Push the files of your Hexo folder to the repository. The public/ folder is not (and should not be) uploaded by default, make sure the .gitignore file contains public/ line. The folder structure should be roughly similar to this repo.

  4. 使用 node --version 检查你在本地机器上使用的 Node.js 版本。记下主要版本(例如 v16.y.z

    ¥Check what version of Node.js you are using on your local machine with node --version. Make a note of the major version (e.g., v16.y.z)

  5. .gitlab-ci.yml 文件添加到你的 repo 的根文件夹中(与 _config.yml 和 package.json 一起),内容如下(将 16 替换为你在上一步中记下的 Node.js 主版本):

    ¥Add .gitlab-ci.yml file to the root folder of your repo (alongside _config.yml & package.json) with the following content (replacing 16 with the major version of Node.js you noted in previous step):

image: node:16-alpine
cache:
paths:
- node_modules/

before_script:
- npm install hexo-cli -g
- npm install

pages:
script:
- npm run build
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  1. 一旦 GitLab CI 完成部署作业,username.gitlab.io 应该启动并运行,

    ¥username.gitlab.io should be up and running, once GitLab CI finishes the deployment job,

  2. (可选)如果你希望检查生成的站点资源(html、css、js 等),可以在 作业工件 中找到它们。

    ¥(Optional) If you wish to inspect the generated site assets (html, css, js, etc), they can be found in the job artifact.

项目页面

¥Project page

如果你希望在 GitLab 上有一个项目页面:

¥If you prefer to have a project page on GitLab:

  1. 转到设置>常规>高级>更改路径。将值更改为名称,以便网站可在username.gitlab.io/repository上访问。可以是任何名称,例如 blog 或 hexo。

    ¥Go to Settings > General > Advanced > Change path. Change the value to a name, so the website is available at username.gitlab.io/repository. It can be any name, like blog or hexo.

  2. 编辑 _config.yml,将 url: 值更改为 https://username.gitlab.io/repository

    ¥Edit _config.yml, change the url: value to https://username.gitlab.io/repository.

  3. 提交并推送。

    ¥Commit and push.

有用的链接

¥Useful links