创建一个名为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.
通过“设置”>“CI/CD”>“运行器”>“为此项目启用共享运行器”启用共享运行器。
¥Enable Shared Runners via Settings > CI/CD > Runners > Enable shared runners for this project.
将 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 containspublic/
line. The folder structure should be roughly similar to this repo.使用
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
)将
.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 (replacing16
with the major version of Node.js you noted in previous step):
image: node:16-alpine |
一旦 GitLab CI 完成部署作业,username.gitlab.io 应该启动并运行,
¥username.gitlab.io should be up and running, once GitLab CI finishes the deployment job,
(可选)如果你希望检查生成的站点资源(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:
转到设置>常规>高级>更改路径。将值更改为名称,以便网站可在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.
编辑 _config.yml,将
url:
值更改为https://username.gitlab.io/repository
。¥Edit _config.yml, change the
url:
value tohttps://username.gitlab.io/repository
.提交并推送。
¥Commit and push.
有用的链接
¥Useful links