Hexo笔记

使用Hexo在github上搭建blog的操作笔记.

创建我的博客

  1. 创建仓库, comtu.github.io
  2. 创建两个分支:masterdev
  3. 设置dev为默认分支(因为我们只需要手动管理这个分支上的Hexo网站文件);
    项目–>Settings–>Branches–>Default Branch–>切换默认分支
  4. 使用git clone git@github.com:comtu/comtu.github.io.git 拷贝仓库;
    没有设置默认分支则使用: git git@github.com:comtu/comtu.github.io.git -d dev
  5. 在本地comtu.github.io文件夹下通过Git bash依次
    执行npm install hexohexo initnpm install
    npm install hexo-deployer-git(此时当前分支应显示为dev);
  6. 修改_config.yml中的deploy参数,分支应为master

    在此期间可以进行本地预览:

    hexo clean   #清除项目
    hexo g       #生成html
    hexo s       #开启本地服务
    通过:http://localhost:4000/ 访问本地生成的效果.如果效果满意再如下操作.
    
  7. 依次执行git add .git commit -m "update xxx"git push origin dev 提交网站相关的文件;

  8. 执行hexo g ; hexo d 生成网站并部署到GitHub上。

这样一来,在GitHub上的comtu.github.io仓库就有两个分支,一个hexo分支用来存放网站的原始文件,一个master分支用来存放生成的静态网页。


日常操作

在本地对博客进行修改(添加新博文、修改样式等等)后,通过下面的流程进行管理:

  1. 依次执行git add .git commit -m "update xxx"
    git push origin dev指令将改动推送到GitHub(此时当前分支应为dev);
  2. 然后才执行hexo g -d发布网站到master分支上。

更换电脑操作

当重装电脑之后,或者想在其他电脑上修改博客,可以使用下列步骤:

  1. 使用git clone git@github.com:comtu/comtu.github.io.git 拷贝仓库(默认分支为dev);
  2. 在本地新拷贝的comtu.github.io文件夹下通过Git bash依次执行下列指令:
    npm install hexonpm installnpm install hexo-deployer-git(不需要hexo init这条指令)。

常用命令

1
2
3
4
5
6
7
8
hexo clean #清除项目
hexo new page "pageName" #新建页面
hexo help #查看帮助
hexo version #查看Hexo的版本
hexo n == hexo new "postName" #新建文章
hexo g == hexo generate #生成静态页面至public目录
hexo s == hexo server #开启本地服务(默认端口4000,'ctrl + c'关闭server)
hexo d == hexo deploy #将.deploy目录部署到GitHub
1
2
3
4
5
6
7
#日常工作:
hexo clean #清除项目
hexo g #生成html
hexo s #开启本地服务
hexo d #部署到github

我的博客使用到的插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ npm ls --depth 0
hexo-site@0.0.0 E:\c
+-- hexo@3.3.9
+-- hexo-deployer-git@0.1.0
+-- hexo-generator-archive@0.1.4
+-- hexo-generator-category@0.1.3
+-- hexo-generator-index@0.2.0
+-- hexo-generator-searchdb@1.0.8
+-- hexo-generator-sitemap@1.1.2
+-- hexo-generator-tag@0.2.0
+-- hexo-renderer-ejs@0.2.0
+-- hexo-renderer-marked@0.2.11
+-- hexo-renderer-stylus@0.3.1
+-- hexo-server@0.2.0
`-- hexo-wordcount@3.0.2 #Node 版本7.6.0之前,请安装 2.x 版本 npm install hexo-wordcount@2 --save

其它常用功能:

1
2
3
4
5
6
7
8
9
10
11
12
#更新hexo到最新版 注意:如果使用苹果电脑则需要加 sudo npm update hexo -g 获取权限安装,区间输入密码.
$ npm update hexo -g
#显示项目的所有插件列表
$ npm ls --depth 0
# 安装插件 如: npm install hexo-generator-sitemap --save
$ npm install xxx插件名称 --save
# 卸载插件
$ npm uninstall hexo-generator-sitemap --save

坚持原创技术分享,您的支持将鼓励我继续创作!