搭建自己的Hexo博客

Posted by Chenyawei on 2019-11-22
Words 595 and Reading Time 2 Minutes
Viewed Times

1.安装node.js

Hexo需用通过npm安装,而npm需要node,现在只要安装node 就自带 npm了

1
2
3
4
执行命令查看是否安装成功:

node -v
npm -v
1
2
3
4
5
6
7
安装nmp阿里的命令:
npm install -g cnpm --registry=https://registry.npm.taobao.org

检查是否安装成功:
cnpm -v

cnpm安装软件时会比较快

2.安装git

首先查看电脑是否安装Git,终端输入

1
git

查看是否出现下图内容:

安装git:

1
brew install git

如果之前未安装homebrew,需安装homebrew,在终端输入:
1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

3.安装hexo

1
2
3
4
5
6
7
8
sudo su 进入root用户,执行下列命令安装:

cnpm install hexo-cli -g
或者:
npm install hexo-cli -g

查看是否安装成功:
hexo -v

4.搭建hexo

1
2
3
4
hexo init blog  //初始化
cd blog //进入文件夹blog
npm install //安装
运行:==hexo s== (浏览器里输入地址 localhost:4000 即可看到效果)

5.部署到GitHub

  • 创建一个xxx.github.io的public仓库

  • 安装一个Git的插件:

    1
    cnpm install --save hexo-deployer-git
  • 修改站点配置文件(_config.yml),修改 depoly :

    1
    2
    3
    4
    deploy:
    type: git
    repo: https://github.com/chenyawei1227/chenyawei1227.github.io.git <所建仓库地址>
    branch: master
    1
    2
    3
    4
    5
    6
    7
    8
    9
    修改主题后启动如果报如下错误:
    extends includes/layout.pug block content include includes/recent-posts.pug include includes/partial

    则执行如下命令可解决:
    npm install --save hexo-renderer-jade hexo-generator-feed hexo-generator-sitemap hexo-browsersync hexo-generator-archive

    hexo clean

    hexo deploy
  • 部署

    1
    2
    3
    4
    5
    hexo clean  //清理
    hexo g //生产页面
    hexo d //部署到GitHub

    浏览器访问:https://chenyawei1227.github.io 查看到效果。

6.更改主题

hexo的主题很多,官网的主题:https://hexo.io/themes/
这里以Cxo主题为例:

1
2
3
4
5
6
7
8
9
10
11
#进入到themes文件夹下,下载主题:
git clone https://github.com/Longlongyu/hexo-theme-Cxo Cxo

# 修改 _config.yml 配置
theme: Cxo

执行:
hexo clean
hexo deploy

浏览器访问:https://chenyawei.github1227.io 查看到效果。

7.创建新文章

1
2
3
hexo new '文章名'

就可以在blog的source文件夹里看到

常用指令:

1
2
3
4
5
6
7
8
9
10
11
npm install hexo-cli -g 
hexo init
npm install
hexo s
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help #查看帮助
hexo version #查看Hexo的版本

notice

欢迎访问 chenyawei 的博客, 若有问题或者有好的建议欢迎留言,笔者看到之后会及时回复。 评论点赞需要github账号登录,如果没有账号的话请点击 github 注册, 谢谢 !

If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !