6.4 KiB
title | excerpt | date | updated | tags | |||
---|---|---|---|---|---|---|---|
How to create a Hexo blog using GitLab and Netlify | Deploy a Hexo website/blog using Netlify from a GitLab repo. | 2018-09-21 | 2020-11-17 |
|
Refer to the this guide (co-authored by me) if you prefer to use GitLab Pages instead of Netlify.
Create a website/blog using Hexo on GitLab Pages for free using the following guide. Refer to my {% post_link hexo-blog-github 'another guide' %} for GitHub Pages.
GitLab project
-
Register a free GitLab account or use your current one.
-
Fork the repo of this blog.
-
Shared Runners should be enabled. Go to your (forked) project
Settings -> CI / CD -> Shared Runners
. -
Change project website to a user website. This is so that the website's home page is username.gitlab.io, instead of username.gitlab.io/hexo. Go to
Settings -> General -> Advanced -> Change path
. Change the value to username.gitlab.io, where username is your username on GitLab. -
You can start writing a new post straight away without installing Hexo. You still need to change the blog's name and favicon though (how-to).
- To create a new post (through GitLab.com), create a new
<post-title>.md
file insource/_posts
folder. - Start with the following header/front-matter:
--- title: Test page date: yyyy-mm-dd hh:mm:ss tags: categories: ---
- To create a new post (through GitLab.com), create a new
-
After you create a new post, the website can be accessed on username.gitlab.io or the link shown on your project
Settings -> Pages
. Read on if you prefer to manage the blog from your workstation.
Installation
- Having Hexo means you can debug locally, rather than waiting for CI. You can even run a local server to preview your blog (see step 6 below).
- Clone your repo to your workstation.
- Install Node.js and Hexo using the official guide.
- Create a new post. Then generate static files to check for any error. You should always do this before pushing/merging commits to the
master
branch.
$ hexo generate
- (Optional) Start Hexo server on
http://localhost:4000
to preview the blog.
$ hexo server
More info: Server
- Git add, commit and push the file to your GitHub repo.
$ git add 'source/_posts/your-post.md'
$ git commit -a -m 'Commit Message'
$ git push -u
-
The generated
public
andnode_modules
are ignored, as CI will generate them during build.- I have migrated to Netlify and removed my GitLab page.
- Since I don't have a gitlab page any more, I removed the deploy command in the
.gitlab-ci.yml
. - The config now has two parts. To use in gitlab page, simply uncomment the second part and comment out the first part.
- Make sure you {% post_link validity-gitlab-ci-config 'double-check' %} the CI config before you push.
-
Check the build status by going to your project
CI /CD -> Pipelines
. Due to the limitation ofhexo
, the build will always pass even when there is error. Check the Jobs log, look for any error after$ hexo deploy
. -
If there is no error, the generated website can be accessed on
<your-username>.gitlab.io/
or the link shown on your projectSettings -> Pages
.
Writing
- Create a new post (using Hexo)
$ hexo new "My New Post"
My-New-Post.md
is created to thesource/_posts
folder, with the following header/front-matter:
---
title: My New Post
date: yyyy-mm-dd hh:mm:ss
tags:
categories:
---
More info: Writing
Configuration
Naming
Change the website's author and name:
title:
excerpt:
description:
author:
Change the theme's setting:
menu:
GitLab: <your-gitlab-project-link>
# Customize /about page
nickname:
description:
Favicon
RealFaviconGenerator provides a web-based tool to generate favicons with wide compatibility.
- Upload your favicon (at least 260x260) and configure however you want.
- Install the generated package to
themes/typing/source
folder. Make you replace all existing files. - Edit
themes/typing/layout/_partial/head.ejs
. Change thecolor
values ofmask-icon
andmsapplication-TileColor
to the values you configured on the generator. - Check for any error using
hexo generate
(you should do this before you push any commit). - Commit and push.
- Check your favicon with the favicon checker.
Project page
If you prefer to have a project page on GitLab:
- Go to
Settings -> General -> Advanced -> Change path
. Change the value to a name, so the website is available at username.gitlab.io/name. It can be any name, like blog or hexo. - Edit _config.yml, change the
root:
value from""
to"name"
. - Commit and push.
Remove fork relationship
If you don't have any plan to send merge requests to the upstream, you can remove fork relationship permanently by going to Settings -> General -> Advanced -> Remove fork relationship
.
Useful links:
Configuration files for this blog deployment:
Docs: