Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
安装hexo
在安装环境都已经配置完成的前提下
git
,node.js
- 终端执行如下命令
sudo npm install -g hexo
- 初始化,终端cd到一个指定的目录(我在~/Documents/目录下)执行如下命令
hexo init <folder>
- 终端cd到目录下,安装npm
cd <folder>
npm install
- 开启hexo服务,就可以在本地(本地预览地址
http://localhost:4000
)预览博客主页了
hexo s # 或者hexo server
Github Pages设置
- 在gitHub中创建一个项目,并且将本地安装的项目上传到gitHub中
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/MavisYang/hexo-blog.git
git push -u origin master
- 在setting中开启GitHub Pages
- 选中master,显示
Your site is published at https://mavisyang.github.io/
成功(如图所示)
关联已有的github
- 打开hexo创建文件夹下的_config.yml配置文件
eploy:
type: git
repository: https://github.com/MavisYang/mavisyang.github.io.git
branch: master
- 在hexo文件夹目录下执行(生成)
hexo g # 或者hexo generate
- 如果报错,则执行
npm install hexo --save
- 再执行命令(部署到git上)
hexo d
- 如果报错,则执行
npm install hexo-deployer-git --save
- 然后再执行hexo g和hexo d
添加博客
hexo new 'post' # 写博客
hexo clean # 清除缓存文件
hexo g # 生成新的文件
hexo d # 同步部署到github端
完成
命令
-
hexo g -w
-
hexo list route
-
hexo list post
-
npm install hexo -g #安装Hexo
-
npm update hexo -g #升级
-
hexo init #初始化博客
-
命令简写
-
hexo n "我的博客" == hexo new "我的博客" #新建文章
-
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 #清除缓存,若是网页正常情况下可以忽略这条命令
添加主题
选择了
next
设置语言
设置语言时,虽然已经设置了简体中文
language: zh-Hans
,但是页面还是英文。
PS:使用hexo clean清理下。然后再使用hexo s 预览。事实上,这个方法在遇到很多问题的时候都是通用的。