Before you start, you need to install Git and node.js on your computer. You can use the Homebrew command line tool to install Git and node.js on your Mac.
Install Homebrew
Enter the following command in the command line tool, if you have already installed Homebrew, you can ignore it
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrew install node.js
brew install node
After installation, you can use the command to check whether the installation is successful.
Check node
node -v
Output result:
v12.14.1
Check if npm is installed successfully, npm is a package management tool for node.js, use it to install hexo
nmp -v
Output result:
6.13.4
Homebrew install git
brew install git
Check if git is installed successfully
git -v
Output result:
git version 2.24.3 (Apple Git-128)
Install hexo using npm
sudo npm install -g hexo-cli
After the installation is complete, create a blog folder in Desktop and initialize our blog under this folder
cd ~/Desktop && mkdir blog && cd blog
Perform blog initialization operations in the file directory
# 会下载一些node.js的依赖文件
hexo init
After the initialization is successful, perform the preview operation in the blog directory
hexo s
When you see the following output, you can preview the blog we created
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
The preview effect is as follows
Configure client git add SSH Key to github
If it has already been configured, this step can ignore
entering the command to configure the user name and account on the command line
git config --global user.name "username"
git config --global user.email "[email protected]"
Which username
is your user name, [email protected]
your github login email
is then generated by the terminal command SSH Key
ssh-keygen -t rsa -C "[email protected]"
If you have already created will be Overwrite (y/n)? n
prompted to enter n
, if not create too will ask us to enter a password, and then enter all the way down the line, will be executed after completion of ~/.ssh/id_rsa.pub
generating key you want to use the directory.
You can use the command line to output the key and copy
cat ~/.ssh/id_rsa.pub
Or you can find this file, open it, and copy the contents.
Log in to github account to find setting
First click SSH and GPG keys
and then click New SSH key
into the page configuration of SSH Key
Then enter the content of the copied key
Click Add SSH Key
to
Local blog linked to Github homepage
Login Github and create a name for username.githug.io
the warehouse, such as my name for the warehouse Johnson8888.github.io
because I have created over, it will be displayed in red, if too create, a green, and then click Create. Remember to choose Public
, deny no access.
Then the command to switch to the local directory blog cd ~/Desktop/blog
Run
sudo npm install hexo-deployer-git --save
Modify the configuration file and start ~/Desktop/blog/_config.yml
modifying deploy
part
deploy:
type: git
repo: [email protected]:Johnson8888/Johnson8888.github.io.git
branch: master
Then you can push the blog to github and
execute it on the command line
#生成我们想要的博客文件
hexo g
#将本地的博客文件push到github
hexo d
hexo d
After successful execution, you can check out our Blog the
Start blogging
Execute on the command line
hexo new firstPage.md
Will ~/Desktop/blog/source/_post
generate a directory firstPage.md
to open this file can be fun to write a blog
re-run after finishing
hexo g
hexo d
You can sync the blog to github
All
- Apply for a domain name to point to the blog, so that you can directly use the domain name to visit
- hexo supports many template styles can go to the official website choose your favorite use
Attach hexo common commands
hexo n "博客名称" => hexo new "博客名称" #这两个都是创建新文章,前者是简写模式
hexo p => hexo publish
hexo g => hexo generate #生成
hexo s => hexo server #启动服务预览
hexo d => hexo deploy #部署
hexo server #Hexo 会监视文件变动并自动更新,无须重启服务器。
hexo server -s #静态模式
hexo server -p 5000 #更改端口
hexo server -i 192.168.1.1 #自定义IP
hexo clean #清除缓存,网页正常情况下可以忽略此条命令
hexo g #生成静态网页
hexo d #开始部署