1. Introduction to Hexo
Hexo is a concise, efficient, open-source static blog generator built with Node.js. Hexo can render Markdown into static HTML files extremely quickly. Like Jekyll, Ghost, and Octopress, it can be used to create a blog.
Hexo has the following advantages:
- It uses Node.js, so setting up the environment is simple. Setting up a Jekyll environment is a real pain.
- It is easy to host on GitHub Pages. Since Hexo generates HTML, deployment is very convenient.
- It supports Markdown.
2. Installing Hexo
After installing Node.js and NPM, it is recommended to switch to a domestic NPM mirror to speed up dependency installation.
| |
Install Hexo.
| |
Initialize Hexo.
| |
This generates files such as scaffolds, drafts, public, db.json, _config.yml, package.json, and theme.
Start the service locally; the default port is 4000.
| |
3. Migrating Posts from Ghost
Since the blog was previously built with Ghost, you need to export the blog data in JSON format from the Ghost admin panel. Then, with a Hexo plugin, convert the JSON data into Markdown files.
Install hexo-migrator-ghost.
| |
Import the data and convert it to Markdown files.
| |
Once it finishes, a Markdown file for each post is generated automatically under the source directory.
4. Publishing to GitHub Pages
Step one: create a new project named your_name.github.io on GitHub.
Step two: configure the repo in _config.yml.
| |
Step three: generate the HTML.
| |
Step four: deploy to GitHub Pages.
| |
Enter your account and password when prompted to complete the deployment. Visit the blog at http://your_name.github.io.
5. Automated Publishing with CI
Since GitHub Pages is used only as the publishing address for the blog, you still need another repository to host the Hexo project and the Markdown source files.
Step one: on GitHub’s https://github.com/settings/keys page, generate a pair of SSH keys, then click [Add SSH key] and paste in the public key.
Step two: on GitLab’s [settings/ci_cd] page, under [Secret variables], add an environment variable named DEPLOY_KEY whose value is the private key.
Step three: configure the CI pipeline. Use GitLab to host the Hexo source repository and publish automatically to GitHub Pages through CI.
In the root directory, create a new file named .gitlab-ci.yml with the following content:
| |
Without a CI configuration, you have to generate the HTML files locally and then deploy them to GitHub Pages. With CI configured, all you need to do now is commit the Markdown files to GitLab, and GitLab CI completes the deployment automatically.
