First to Hexo (Building Blog using Hexo and Github)

Hexo Installation

  • Environment: Ubuntu=24.4

Install Node.js

use nvm

1
2
3
4
5
6
7
8
9
10
11
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# download and install Node.js (you may need to restart the terminal)
nvm install 22

# verifies the right Node.js version is in the environment
node -v # should print `v22.11.0`

# verifies the right npm version is in the environment
npm -v # should print `10.9.0`

Other methods can be found in Nodejs website.

Install Git

1
sudo apt-get install git

Install Hexo

make a folder for Hexo

1
mkdir blog  # `blog` in my case.

install hexo-cli

1
npm install hexo-cli -g

It take a while, because the node_modules has a reputation for being too bloated.

Hexo Usage

Initialize Hexo

  1. goto blog folder

    1
    cd blog
  2. edit config

    use vi:

    1
    vi _config.yml

    or vscode:

    1
    code _config_yml
  3. change the title, subtitle, author and url…

    for example:

    1
    2
    3
    4
    title: dyliu's Blog
    subtitle: 'Documenting my personal experience'
    author: dyliu
    url: https://yourname.github.io/

Create blog page

  1. new page

    1
    hexo new "First-to-Hexo"
  2. edit page in vscode (or something else)

    1
    code source/_posts/First-to-Hexo.md 

Preview the page

use

1
hexo server

to start a local server http://localhost:4000

Deploy on Github

Create Github repository

  1. Sign in (or sign up first) and Create new repository

    It’s name should be yourname.github.io, where yourname is same with your github username, for example ‘dyliu0312.github.io’ in my case, to get to the page simply using https://dyliu0312.github.io.

    Otherwise, it’l be http://yourname.github.io/your_repository_name.github.io.

  2. Generate ssh key

  • git config

    1
    2
    git config --global user.name "yourname"
    git config --global user.email "youremail"
  • use

    1
    ssh-keygen -t ed25519 -C "your_email@example.com"

    to generate a pair of ssh key in local machine.

  1. Add ssh key to repository
  • Open the public key .ssh/id_ed25519.pub, and copy the context.

  • Turn to repository page, click Settings, and then click Deploy keys in Security to save new ssh key.

Edit config

revise the _config.yamlfile:

1
2
3
4
deploy:
type: git
repo: git@github.com:yourname/yourname.github.io.git
brach: master

Deploy

  1. Install hexo-deployer-git

    1
    npm install hexo-deployer-git --save
  2. Clean

    1
    hexo clean
  3. Generate

    1
    hexo g
  4. Deploy

    1
    hexo d

Reference

https://blog.csdn.net/weixin_43883917/article/details/143885553
https://training.github.com/downloads/github-git-cheat-sheet/
https://blog.csdn.net/m0_53127626/article/details/136090280
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
https://mini-pi.github.io/2024/02/28/how-to-make-blog-wedsite/


First to Hexo (Building Blog using Hexo and Github)
https://dyliu0312.github.io/blog.github.io/2024/11/30/First-to-Hexo/
Author
dyliu
Posted on
November 30, 2024
Licensed under