介绍使用Hexo搭建博客
[TOC]
环境
mac 10.14
默认已安装好了HomeBrew和Git
搭建
安装Node.js环境
先检测电脑山管是否安装有Node.js环境,能正确显示版本号即表示node安装成功(mac不自带Node.js环境)
1 | npm -v |
安装Node.js(Hexo是基于Node.js环境的)
1 | brew install node |
安装npm
1 | $ npm install |
安装Hexo
安装
1 | -g表示全局安装 |
初始化博客
1 | $ cd myblog # 创建并进入存储博客的目录(myblog) |
生成并运行服务
执行下述命令生成本地网页文件并开启服务器,然后通过http://localhost:4000查看本地博客。
1 | $ hexo g # Generate static files |
关联GitHub
修改myblog目录下的_config.yml文件
1 | deploy: |
双线部署
1 | deploy: |
部署发布
1 | $ hexo g |
若执行hexo g
出错则执行npm install hexo --save
,
若执行hexo d
出错则执行npm install hexo-deployer-git --save
。错误修正后再次执行hexo g
和hexo d
上传到服务器
若未关联GitHub,执行hexo d时会提示输入GitHub账号用户名和密码,即:
1 | username for 'https://github.com': |
hexo d
执行成功后便可通过git 仓库地址访问博客,看到的内容和http://localhost:4000相同。
更换Hexo主题
以比较精简的为例 maupassant
1 | $ git clone https://github.com/tufu9441/maupassant-hexo.git themes/maupassant |
将myblog目录下_config.yml里的theme的名称landscape更改为next。
1 | $ hexo g // 生成缓存和静态文件 |
当本地博客部署到服务器后,网页端无变化时可以采用下述命令。
1 | hexo clean // 清楚缓存文件(db.json)和已生成的静态文件(public) |
推荐主题
写个博客
1 | $ hexo new "article title" |
然后执行生成,发布即可
其它知识
当安装的一些插件不需要时,可以卸载
1 | npm uninstall 模块 |